|
-
January 28th, 2009, 06:18 PM
#1
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
-
January 28th, 2009, 08:19 PM
#2
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.
-
January 28th, 2009, 08:24 PM
#3
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
-
January 28th, 2009, 09:27 PM
#4
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!
-
January 29th, 2009, 03:47 AM
#5
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..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
January 29th, 2009, 05:24 AM
#6
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.
Last edited by TT(n); January 29th, 2009 at 05:29 AM.
Reason: speculative
-
January 29th, 2009, 07:20 PM
#7
Re: Combo Box, If Then Statement
From the VB6 tags:
Code:
vbChecked
vbUnchecked
cbGrey
1,0,-1
as I recall.
-
January 29th, 2009, 07:40 PM
#8
Re: Combo Box, If Then Statement
Ahh the good old days,....
I still love to backport to vb6 today though.
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
|