|
-
Feb 24th, 2008, 03:32 PM
#1
Thread Starter
PowerPoster
[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:
Private Sub cboPartTime_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPartTime.SelectedIndexChanged With cboFullTime If cboPartTime.SelectedIndex = 0 Then 'Yes .SelectedIndex = 1 'No Else .SelectedIndex = 0 'Yes End If End With End Sub
Any ideas? Thanks in advance
-
Feb 24th, 2008, 04:41 PM
#2
Hyperactive Member
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 ?
-
Feb 24th, 2008, 05:41 PM
#3
Thread Starter
PowerPoster
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
 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 ?
-
Feb 24th, 2008, 05:50 PM
#4
Thread Starter
PowerPoster
Re: [2005] GroupBox members not changing value....
i even tried
vb Code:
Private Sub ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboFullTime.SelectedIndexChanged, _
cboPartTime.SelectedIndexChanged
Dim objCB As ComboBox = DirectCast(sender, ComboBox)
With objCB
If .Name Is "cboFullTime" Then
Select Case .SelectedIndex
Case 0
cboPartTime.SelectedIndex = 1
Case 1
cboPartTime.SelectedIndex = 0
End Select
ElseIf .Name Is "cboPartTime" Then
Select Case .SelectedIndex
Case 0
cboFullTime.SelectedIndex = 1
Case 1
cboFullTime.SelectedIndex = 0
End Select
End If
End With
End Sub
and get the same error (value of 1 is invalid for selectedindex)
i have two values. yes and no
-
Feb 24th, 2008, 05:57 PM
#5
Thread Starter
PowerPoster
Re: [2005] GroupBox members not changing value....
when i do a breakpoint, i find that
vb Code:
cboPartTime.SelectedIndex = 1
shows as -1 instead of 1
the error is generated when i run the application in the IDE
-
Feb 25th, 2008, 01:18 AM
#6
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?
-
Mar 2nd, 2008, 03:29 PM
#7
Thread Starter
PowerPoster
Re: [2005] GroupBox members not changing value....
 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:
Public Sub PopulateYesNo(ByRef strName As Object) Dim cbo As Combobox = DirectCast(strName, Combobox) With cbo .Items.Add("Yes") .Items.Add("No") End With End Sub
vb Code:
....form load PopulateYesNo(combobox name here)
?
Last edited by BrailleSchool; Mar 2nd, 2008 at 03:42 PM.
-
Mar 2nd, 2008, 04:05 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|