|
-
Jan 20th, 2010, 07:11 PM
#1
Thread Starter
Member
[RESOLVED] Combobox ListIndex
I am trying to have the index value of a selected item in a combobox returned to a variable. Then, if the variable = 1 (which would be the index of th second item in the combobox), I want a groupbox to be hidden (be invisible) on the form. Here is my code...Getting an error that says:
'ListIndex' is not a member of 'System.Windows.Forms.ComboBox'
Code:
Private Sub cbxAccounts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim selection As Integer = CInt(cbxAccounts.ListIndex)
If selection = 1 Then gbxCheck.Hide()
End Sub
-
Jan 20th, 2010, 07:38 PM
#2
Re: Combobox ListIndex
Exactly as the error message: The ComboBox class has no member named "ListIndex". Have you looked to see what members the ComboBox class has and which one does what you want? All you have to do is type the dot after the variable name and Intellisense will show you a list of all members, and if you want more information you can simply consult the documentation.
http://msdn.microsoft.com/en-us/libr....combobox.aspx
-
Jan 20th, 2010, 07:47 PM
#3
Thread Starter
Member
Re: Combobox ListIndex
I found what I need, but for some reason the Groupbox is not being hidden when the item is selected in the combobox. back to the book I go.
-
Jan 20th, 2010, 09:08 PM
#4
Re: Combobox ListIndex
Which item are you selecting? If you're looking for the first item then that would be at index 0, not index 1. All lists in .NET are 0-based, so I suspect that you're using VB6 example code.
-
Jan 20th, 2010, 10:02 PM
#5
Thread Starter
Member
Re: Combobox ListIndex
I am selecting the second item.
-
Jan 20th, 2010, 10:39 PM
#6
Thread Starter
Member
Re: [RESOLVED] Combobox ListIndex
This works now. It took some work, but I got it going. Here is the code:
Code:
Private Sub cbxAccounts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxAccounts.SelectedIndexChanged
' Hide "Check" Groupbox when "Savings" is selected from "Accounts" Combobox
Dim selection As String = cbxAccounts.SelectedItem
If selection = "Savings" Then gbxCheck.Visible = False Else gbxCheck.Visible = True
End Sub
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
|