Results 1 to 8 of 8

Thread: [RESOLVED] [2005] GroupBox members not changing value....

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] [2005] GroupBox members not changing value....

    Hi all,

    I have a group box with many controls on it. What I am looking to do is when the Part-time combobox equals Yes, the Full-time combobox equals no (or vice versa)

    I have tried many different things and I get no errors, yet the values do not change for me.

    This is what I currently have. I have tried a for each loop in the groupboxes controls and that doesnt even work for me
    vb Code:
    1. Private Sub cboPartTime_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPartTime.SelectedIndexChanged
    2.         With cboFullTime
    3.             If cboPartTime.SelectedIndex = 0 Then 'Yes
    4.                 .SelectedIndex = 1 'No
    5.             Else
    6.                 .SelectedIndex = 0 'Yes
    7.             End If
    8.         End With
    9.     End Sub
    Any ideas? Thanks in advance

  2. #2
    Hyperactive Member gnaver's Avatar
    Join Date
    Jul 2005
    Location
    Denmark/Sweden
    Posts
    289

    Re: [2005] GroupBox members not changing value....

    this works but is a little ugly code...

    Code:
       Private Sub combo_change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFullTime.SelectedIndexChanged, cboPartTime.SelectedIndexChanged
            If CType(sender, ComboBox).Name = "cboFullTime" Then
                Select Case cboFullTime.SelectedIndex
                    Case 0
                        cboPartTime.SelectedIndex = 1
                    Case 1
                        cboPartTime.SelectedIndex = 0
                End Select
            Else
                Select Case cboPartTime.SelectedIndex
                    Case 0
                        cboFullTime.SelectedIndex = 1
                    Case 1
                        cboFullTime.SelectedIndex = 0
                End Select
            End If
        End Sub
    dont know if this was what you wanted ?

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] GroupBox members not changing value....

    i already tried something like this and got an ArgumentOutOfRangeException error. got this error with your code too

    Quote Originally Posted by gnaver
    this works but is a little ugly code...

    Code:
       Private Sub combo_change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFullTime.SelectedIndexChanged, cboPartTime.SelectedIndexChanged
            If CType(sender, ComboBox).Name = "cboFullTime" Then
                Select Case cboFullTime.SelectedIndex
                    Case 0
                        cboPartTime.SelectedIndex = 1
                    Case 1
                        cboPartTime.SelectedIndex = 0
                End Select
            Else
                Select Case cboPartTime.SelectedIndex
                    Case 0
                        cboFullTime.SelectedIndex = 1
                    Case 1
                        cboFullTime.SelectedIndex = 0
                End Select
            End If
        End Sub
    dont know if this was what you wanted ?

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] GroupBox members not changing value....

    i even tried
    vb Code:
    1. Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboFullTime.SelectedIndexChanged, _
    2.                                                                                                            cboPartTime.SelectedIndexChanged
    3.  
    4.         Dim objCB As ComboBox = DirectCast(sender, ComboBox)
    5.  
    6.         With objCB
    7.             If .Name Is "cboFullTime" Then
    8.                 Select Case .SelectedIndex
    9.                     Case 0
    10.                         cboPartTime.SelectedIndex = 1
    11.                     Case 1
    12.                         cboPartTime.SelectedIndex = 0
    13.                 End Select
    14.             ElseIf .Name Is "cboPartTime" Then
    15.                 Select Case .SelectedIndex
    16.                     Case 0
    17.                         cboFullTime.SelectedIndex = 1
    18.                     Case 1
    19.                         cboFullTime.SelectedIndex = 0
    20.                 End Select
    21.             End If
    22.         End With
    23.     End Sub
    and get the same error (value of 1 is invalid for selectedindex)
    i have two values. yes and no

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] GroupBox members not changing value....

    when i do a breakpoint, i find that
    vb Code:
    1. cboPartTime.SelectedIndex = 1
    shows as -1 instead of 1

    the error is generated when i run the application in the IDE

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] GroupBox members not changing value....

    I don't quite understand why you have two ComboBoxes for the same value. That's like having a Male ComboBox and a Female ComboBox, then selecting a different value in each. You'd just have a Gender ComboBox and select Male or Female. Why is your situation any different?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: [2005] GroupBox members not changing value....

    Quote Originally Posted by jmcilhinney
    I don't quite understand why you have two ComboBoxes for the same value. That's like having a Male ComboBox and a Female ComboBox, then selecting a different value in each. You'd just have a Gender ComboBox and select Male or Female. Why is your situation any different?
    the situation in this instance is specifying if a user is full-time or part-time, if they are full-time, they cant be part-time too or vice versa. therefore, the value would have to be different (so if someone selects full-time = yes, the part-time = no automatically, or vice versa). also, my question is, if you have many comboboxes that have yes/no values, how can you specify these values once and then populate the relevant comboboxes? would you do something like:
    vb Code:
    1. Public Sub PopulateYesNo(ByRef strName As Object)
    2.     Dim cbo As Combobox = DirectCast(strName, Combobox)
    3.  
    4.     With cbo
    5.         .Items.Add("Yes")
    6.         .Items.Add("No")
    7.     End With
    8. End Sub
    vb Code:
    1. ....form load
    2.  
    3. PopulateYesNo(combobox name here)
    ?

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] GroupBox members not changing value....

    Generally, people use radiobutton controls for this kind of thing. If you put them side by side, they may not take much more space than the combobox.

    As for your question, why not pass in a combobox item directly, rather than an object. That way you don't have to do the casting. The sub won't work with any other type anyways.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width