I have a ComboBox related to a DataView that took a populated DataTable . This DataTable has three columns. Before the DataView bound to a ComboBox , I add another column and set some values.
Dim table As DataTable = _retrieve.GetAllVersionsTable() table.Columns.Add("FirstRow", GetType(Boolean)) Dim row As DataRow = table.NewRow() row("ID") = -1 row("SomeValue") = -1 row("SomeText") = "N/A" row("FirstRow") = True 'Fort sorting... Dim view As DataView = New DataView(table) view.Sort = "FirstRow DESC, SomeText DESC" table.Rows.InsertAt(row, 0) comboBox.DataSource = view comboBox.ValueMember = "ID" comboBox.DisplayMember = "SomeText"
Subsequently, I retrieve the same data and create a new DataTable and bind it to the DataGridView in a different form. From this form, I set the value for the identity column from the selected row in the DataGridView .
When I return to the first form using ComboBox , I want to select the ComboBox line, which has the same value that I set from the second form, bound to the ValueMember property. I thought SelectedValue would work for this, but it is not. What else can I do?
comboBox.SelectedValue = myIdentityValue
Since the strings are different, I cannot use SelectedItem . Is there a way to select a suitable row without having to iterate over all existing rows?
source share