element Posted November 1, 2003 Posted November 1, 2003 Hi, I have a DataBound Combo box in VB.NET bound to a DataSet. It displays row data. I need to be able to modify which row is selected from code in order for my program to work properly. Basically my code returns a Row, which is from the same dataset table as the combo's bound member, which needs to be "selected". I cannot use the .SelectedItem method to do it, as it does nothing.... Thanks in advance, Tom Quote
*Experts* jfackler Posted November 1, 2003 *Experts* Posted November 1, 2003 (edited) Dim dr As DataRow dr = the datarow you returned from your code Dim dv As DataView dv = DataSet11.Tables(0).DefaultView() dv.Sort = DataSet11.Tables(0).DefaultView.Sort.ToString ComboBox1.SelectedIndex = dv.Find(dr(DataSet11.Tables(0).DefaultView.Sort.ToString))'returns the index of the row you have returned in code and selects the combobox item that corresponds to it Jon Edited November 1, 2003 by jfackler Quote
element Posted November 2, 2003 Author Posted November 2, 2003 jfackler, Thank you for your response. I did eventually manage to get it to work with this rediculous (but working) code: Dim o As Object, d As DataRowView, i As Integer = 0 For Each o In cboCDs.Items If TypeOf o Is DataRowView Then d = DirectCast(o, DataRowView) If d("tocname") = tag.CDName Then cboCDs.SelectedIndex = i Exit For End If End If i += 1 Next However I implemented your code and it works fine also, if not better ;) I did infact need to specify how my DataSet was sorted after the DataSet was loaded using this code: m_Data.ReadXml(x, XmlReadMode.ReadSchema) m_Data.Tables(CDTABLE).DefaultView.Sort = "tocname" Thanks again, Tom Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.