Results 1 to 6 of 6

Thread: [RESOLVED] Combobox ListIndex

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    44

    Resolved [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

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

    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
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    44

    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.

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

    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.
    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

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    44

    Re: Combobox ListIndex

    I am selecting the second item.

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2009
    Posts
    44

    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
  •  



Click Here to Expand Forum to Full Width