Results 1 to 7 of 7

Thread: changing the default shown value in a drop down list from code in .net

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2004
    Posts
    48

    changing the default shown value in a drop down list from code in .net

    Hey,
    How would I go about changing the default shown value in a drop down list from code in vb.net. I want to pass it parameters and change what is shown by default depending on what they are.


    Thanx ~Cran56

  2. #2
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    VB Code:
    1. comboBox1.SelectedIndex = index

    that's assuming there's data in the collection. Otherwise, that will give an error. Is that your case?

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2004
    Posts
    48
    i'm not dynamically populating it. It has a constant collection of items.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    then that should work perfectly for you.

    you can also do it like this :
    VB Code:
    1. ComboBox1.SelectedItem = ComboBox1.Items.Item(index)

    the latter is just more to type.

  5. #5
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11
    does that still work if the data in the combo box is from a data source?

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    yep. as long as you know the index of the value you're after. Just be sure to call upon the index AFTER the box is populated otherwise, an error is generated.

  7. #7
    New Member
    Join Date
    Jul 2004
    Location
    tn
    Posts
    11
    thanks I will try that

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