Question

Alright Gents,

Im trying to search a vb.net combo box for an item. The combo box is already bound to dataset. The display member is set to display just a single column of the selected record. I had it set initially so the objects displayed in the combo were a customized class. In this class I specified all the properties I wanted to keep track of and that seemed to work well. However now that I am using the combo box in its bound state it is much more difficult to manipulate the data.

Mission: To have the user type a number, if the number is contained in the ComboBox, the combo box should then move to that record so that all the other items bound to that control will update as well.

Research: I have looked into the System.Windows.Forms.BingingManagerBase class and that seems to have the information I need. I just can't figure out the bridge between that and what I'm trying to do. I want to throw something together so I tried to simply do a SQL search against the dataset for the text in the combobox. Unfortunately that requires late binding and my targeted version of the .Net compact framework does not support that.

Here is an example of the late binding I was attempting. (Im working with VB.net 2005, Compact Framework 3.5 I believe:

For i as integer = 0 to combobox.items.count - 1 

    dim Dsr as Dataset.Row  
    dim dv as dataview

    Dsr = DirectCase(Dv.row, Dataset.Row) 

    If Dsr(i).DesiredColumn = DesiredRow.Desiredcolumn then 
    'Do such and such code
    End If 

Next 

I want to be able to search the dataset for a specific record matching a query. After I find that row matching the query I want to be able to move my combo box to the row found in the SQL query. The main problem seems to be that the Combo works in Datarowviews and my datasets are mostly cast to rows pertaining to the DS.

Anyone have some insight on this it would be much appreciated.

Thanks again!

Was it helpful?

Solution 2

For i As Integer = 0 To ComboBox.Items.Count - 1
                Dim drv As System.Data.DataRowView = Nothing
                Dim desiredColumn As String = String.Empty

                drv = DirectCast(ComboBox.Items.Item(i), DataRowView)
                desiredColumn = Convert.ToString(drv("Tag"))

                Debug.WriteLine(desiredColumn)
            Next

This seems to find the column value for every record in the combo box allowing me to find the correct index of the text I am searching for. Like I said though, if I could find a way to search through the list of items in the combobox without having to address each one, I would be grateful.

OTHER TIPS

If you know the item that should be set as selected in the combobox you can just set the ComboBox.SelectedItem Property

If you actually do really need to loop through all the items bound to the combobox then once you reach the correct one you can set the ComboBox.SelectedIndex Property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top