loading xml into combo box shows System.Data.DataRowView

acorn

Active member
Joined
Mar 8, 2008
Messages
32
Programming Experience
5-10
Hi there.
I've got an xml file that i'm trying to bind to a combo box. i'm trying to save the selected value of the combo to another text box.
when my form initially loads, the text box shows System.Data.DataRowView
instead of the currently selected value.
i've read on other posts that this can happen if you don't have the right column names specified. but i'm pretty sure that's not my problem... because i'm not using string values for names, but referencing them by index. also, the actual combo boxes do display the list of values...

Here's the code to bind the xml data:

With Me.cmboSectionAQ1
.DataSource = dsYNDNK.Tables(0)
.DisplayMember = dsYNDNK.Tables(0).Columns(0).ColumnName
.ValueMember = dsYNDNK.Tables(0).Columns(1).ColumnName
End With

and the code to save / show the currently selected value in a separate text box:

Private Sub cmboSectionAQ1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmboSectionAQ1.SelectedIndexChanged
SelectedValueTextBox.Text = cmboSectionAQ1.SelectedValue.ToString
End Sub

It's in the selectedvaluetextbox that the system is showing "system.data.datarowview"

Any suggestions?
Thanks.
 
Just to elaborate, the reason this is happening is that the SelectedIndexChanged event is being raised when you set the DataSource. At that point you haven't set the ValueMember so the Selectedvalue just returns the SelectedItem, which is a DataRowView. You need to set the DisplayMember and ValueMember before setting the DataSource so that, when SelectedIndexChanged is raised, the SelectedValue returns the correct value.
 
Back
Top