Results 1 to 4 of 4

Thread: Combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Location
    Singapore
    Posts
    13

    Combobox

    I have a windows form with 2 comboboxes. The first combobox is visible while the other is not, until when I select a value in the first combobox, the second combobox will appear. How do I do that?

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

    Re: Combobox

    Handle the SelectedIndexChanged event of the first ComboBox:
    Code:
    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.comboBox2.Visible = (this.comboBox1.SelectedIndex != -1);
    }
    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
    New Member
    Join Date
    Jul 2006
    Location
    Singapore
    Posts
    13

    Re: Combobox

    Thanks for your reply, but it doesn't work. I first set the visible property of the second combobox to false and added your code, but it doesn't work. The second combobox had appeared when the form loads. How?

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

    Re: Combobox

    You can see from the code that the second ComboBox is visible if an item is selected in the first ComboBox and not visible if an item isn't selected. Assuming that you've set the Visible property of the second ComboBox to False in the designer, if your second ComboBox is visible then you have an item selected in your first ComboBox, plain and simple.
    Last edited by jmcilhinney; Aug 21st, 2006 at 09:18 PM.
    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

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