Results 1 to 3 of 3

Thread: combobox default value

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Posts
    150

    combobox default value

    In my Form_Load method I have code that populates a combobox.

    I want the value at item 0 to be set as the default.

    I way of doing this is to set selecteditem to 0 but unfortunitly I have an indexchanged event as well so this is call when the selecteditem is set to 0 in the load event.

    How can i set a default value after the combobox has been populated but I dont want the indexchanged event called at this stage.

    Thanks
    John

  2. #2
    Lively Member
    Join Date
    Jun 2003
    Posts
    89

    Re: combobox default value

    Like this?

    combo.Text = combo.Items[0].ToString();
    - mo! I said MOOOOOOO!!
    - ...yep, that's a cow, alright.

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

    Re: combobox default value

    Firstly, I assume that you mean that you're setting the SelectedIndex to zero, not the SelectedItem. While it's relatively obvious what you mean here, please make the effort to use correct terminology as it can save a lot of confusion.

    If you only want to capture changes made by the user then you should handle the SelectionChangeCommitted event rather than SelectedIndexChanged.
    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