Results 1 to 3 of 3

Thread: Combobox Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    262

    Combobox Question

    Just something basic. How do I get a combobox to have text already displayed when the form loads?

    The comboboxes are created at run-time and have options loaded into them from a database

    I've tried:
    cmbQuestions(x).Text = qID(x)
    cmbQuestions(x).SelectedText = qID(x)
    cmbQuestions(x).SelectedItem = qID(x)

    everytime the form loads the comboboxes have the options in them but nothing default to see (default - what i made earlier from another screen)

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Combobox Question

    An example
    VB Code:
    1. ComboBox1.Items.Add("Test")
    2. ComboBox1.SelectedItem = "Test"

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Combobox Question

    You can also set the SelectedIndex property... Just make sure you don't accidentally set it out of bound
    VB Code:
    1. For i As Integer = 0 To 4
    2.             'Add 5 items to the combobox
    3.             ComboBox1.Items.Add("Item" & i.ToString())
    4.         Next
    5.         'Select the 2nd item
    6.         ComboBox1.SelectedIndex = 1

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