Results 1 to 5 of 5

Thread: combobox first item show when populated

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    combobox first item show when populated

    Hi ,


    I have this combobox that is being populated form a table. This Ive done , now I need it to have a specific item show as default. Since the combobox needs to be indexed, how can I code it to show always this specific item.

    I tried to have

    MyCombobox.GetItemText = "MyItemText"

    but does not work. Any help please. Thanks

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: combobox first item show when populated

    Try this... the items are objects.. if they are strings, just cast them..
    VB Code:
    1. Dim mytest As String
    2. mytest = DirectCast(ComboBox1.Items.Item(0), String) '0 is first item...

  3. #3
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: combobox first item show when populated

    K.. if you just want to select the item... then just call the selectedindex..
    VB Code:
    1. ComboBox1.SelectedIndex = 0 'selects the first item in the collection

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

    Re: combobox first item show when populated

    How have you populated this ComboBox? The most likely ways to select your default value would be to set the SelectedIndex, SelectedItem or SelectedValue property. Which one you use would depend on how you've populated the list and how you can identify the default value.
    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
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: combobox first item show when populated

    hi,

    Still not loading first item. What I am doing is to populate the combobox from database which loads data except that the first item is not showing up. It is getting them sorted so obviously the first one that was entered is not showing up.

    I dont know why cos the field is not indexed and the combobox properties's sorted is set to false. Any ideas why.

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