Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB9.0
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.
 
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 18-Nov-10 6:37am
CGecko166
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I used the group box. It worked well, plus it eliminates a label for each column.
 
That's perfect!! thanks Big Grin | :-D
  Permalink  
Comments
Kschuler at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

didn't see the datarepeater answer before i replied but I will try it too.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 275
1 DamithSL 265
2 CPallini 235
3 Maciej Los 185
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 18 Nov 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100