Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted (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 by jfackler
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...