Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Newbie programmer here. I have a small invoicing application I'm trying to build, but I'm stuck.
There are multiple textboxes that need to be enabled/ disabled in groups through checkboxes, based on how many techs are on the job.

For example, each tech will have separate expenses (airfare, hotel, car, gas, etc.) as well as different working hours (separated into regular, overtime, travel, weekend, etc.).

The idea is to have the first column (tech1) enabled by default, and everything else disabled on load. Then based on checkboxes enable the column for each additional tech.

Each tech has about 20 fields to be enabled/disabled, which means a LOT of code if I need to write a line of code to enable/disable each box. I'm sure there has to be an "easy" way to do this with much less code. But as my opening says, I'm a newbie.

Here is an example of the way I found to do this.

VB
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' first set enabled rest disabled on load
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        TextBox5.Enabled = False
        TextBox6.Enabled = False
        CheckBox2.Enabled = False
    End Sub
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

        'enable second set with checkbox1
        If CheckBox1.Checked = True Then
            TextBox3.Enabled = True
            TextBox4.Enabled = True
            CheckBox2.Enabled = True
        Else
            TextBox3.Enabled = False
            TextBox4.Enabled = False
            CheckBox2.Enabled = False
            TextBox5.Enabled = False
            TextBox6.Enabled = False
        End If
        'in case checkbox 1 is unintentionally unchecked, then rechecked
        If CheckBox1.Checked And CheckBox2.Checked = True Then
            TextBox5.Enabled = True
            TextBox6.Enabled = True
        End If
    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
        'enable third set with checkbox2
        If CheckBox2.Checked = True Then
            TextBox5.Enabled = True
            TextBox6.Enabled = True
        Else
            TextBox5.Enabled = False
            TextBox6.Enabled = False
        End If

    End Sub
End Class
Posted

Try putting each group of textboxes into their own groupbox, and enable/disable the groupbox.

If that doesn't work, put the textboxes into a groupbox, and then when you need to enable/disable the textboxes in a given groupbiox, just iterate through the child controls of the groupbox.
 
Share this answer
 
As a possible alternative to John's answer, you might consider using the DataRepeater control from VB PowerPacks 3.0[^]. This would allow you to have a less cluttered form as the input controls for additional techs would only appear when they are needed.
 
Share this answer
 
I used the group box. It worked well, plus it eliminates a label for each column.

That's perfect!! thanks :-D
 
Share this answer
 
Comments
Kschuler 18-Nov-10 14:08pm    
If you have time, you may want to Accept one of the above as the answer to your question to mark it properly. It's helpful to others searching in the Quick Questions section to know if an answer has been found.
didn't see the datarepeater answer before i replied but I will try it too.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900