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.ÿ :-)
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
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.
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL