Combo Box, If Then Statement
Hi,
I'm trying to create a combo box that, when I select an item, certain checkboxes become checked. I'm sure I can use an If Then statement to do that, but I'm running into a problem and I can't figure it out. I'll post the code below. If my code looks fine, I'll post the error. But, I'm sure I'm messing up somewhere
Thanks
Code:
Private Sub ConfigComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigComboBox.SelectedIndexChanged
If ConfigComboBox.SelectedItem = 0 Then
chkbxKas.Checked = True
End If
End Sub
Re: Combo Box, If Then Statement
It looks like it will compile, but without trying it, it's not worth it to look. OTOH, if you had posted the error and the line # along with the code, it would probably have been answered by now.
Re: Combo Box, If Then Statement
Sorry. I just thought I may have messed the code up.
Here's the error:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string "Minimal Removals [Quick]" to type 'Double' is not valid.
It occurs on line:
Code:
If ConfigComboBox.SelectedItem = 0 Then
Thanks
Re: Combo Box, If Then Statement
Code:
Minimal Removals [Quick]" to type 'Double'
That says it all. Your item selected isn't type Double, and there is no conversion available.
After you type the = sign, it should give you the available options. Use one of them!
Re: Combo Box, If Then Statement
The question here is what type of data is bound to the combobox.. You probably got a "List (Of {Object})" as the bound data.. the better bet here then would be to use "Selectedindex" ..
Code:
Private Sub ConfigComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigComboBox.SelectedIndexChanged
If ConfigComboBox.SelectedIndex = 0 Then
chkbxKas.Checked = True
End If
End Sub
"Selecteditem" will return the selected {Object} , of the bound data .. where you can then use
Code:
Dim ThisItem as {Object} = Ctype(ConfigComboBox.SelectedItem, {Object})
where you can now check exactly what item has been selected..
Gremmy..
Re: Combo Box, If Then Statement
Yup, selectedindex works fine.
One note though:
Code:
chkbxKas.Checked = True
Works.
But I've found that it's inconsistent, and this works every time:
Code:
chkbxKas.CheckState = CheckState.Checked
I assume because there is 3rd possible state, it's best to be explicit.
Re: Combo Box, If Then Statement
From the VB6 tags:
Code:
vbChecked
vbUnchecked
cbGrey
1,0,-1
as I recall.
Re: Combo Box, If Then Statement
Quote:
From the VB6 tags:
Ahh the good old days,....
I still love to backport to vb6 today though.:)