ComboBox - Search and Select


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: ComboBox - Search and Select

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    ComboBox - Search and Select

    [Originally posted by L_Cotten]

    I have a combobox who's style is set to DropDownList. I want to search the list for an item with certain text and then select that item. How would I go about doing that??

    Thanks for your help. :-)

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:ComboBox - Search and Select

    [Originally posted by Torgrim Brochmann]

    Use the items-collection of the combobox. When you create a combo in Visual Basic, you have the option of adding indexes to all of your entries as the second parameter of the add-method (as long as you're not directly loading from a database, that is). This index is zero-based, which means that you can loop trough the combo using this index from 0 to the combos items.count-method.

    Say you do something like:

    'MyCombo is the combobox
    Dim i as Integer
    Dim ReturnValues(MyCombo.Index.Count) as Integer

    For i = 0 to MyCombo.Items.count - 1
    ReturnValues(i) = MyCombo.Index(i).Value
    Next i

    What you also could do was to load all the values in to an array as you read them into the combobox, and then read from the array instead of reading form the combobox, as this would make your code faster, more efficient and easier to read and maintain.

    Good coding!

    Torgrim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center