DisplayMember is being ignored

G

Guest

Hi,

I have the following code to set the DataSource of a ComboBox to a certain
table in an untyped DataSet, and I also want to set the DisplayMamaber of the
ComboBox to a certain column:

cmbID.DataSource = Me.Ds.Tables("Groups")
Dim str As String = Me.Ds.Tables("Groups").Columns("CustomerID").ColumnName
Me.cmbCustomerID.DisplayMember = str

Problem is, I have stepped through this code, and str is assigned the value
"CustomerID". I then step over the line where str is assigned as the
DisplayMember. However, the value of DisplayMember remains at "". The
ComboBox is populated with the appropriate number of items, but each simply
says "System.Data.DataRowView".

Any ideas? The code was fine, no changes were made, it just suddenly
doesn't like it. I then changed some code in another class, ran it, and the
ComboBox populated fine. I Ran it again, broken again. Most baffling.
 
G

Guest

As I said, it is an untyped DataSet, and therefore the CustomerID property
available with a Typed DataSet is not available here.

I managed to sort it out by setting the DisplayMember before setting the
DataSource. Don't know why it works but it did.
 
D

Dmytro Lapshyn [MVP]

What's specified in DisplayMember is the data column name, not a property
name. Therefore, should work for untyped datasets as well.
 
G

Guest

I understand that the value needed for the DisplayMember is a column name,
but if the Dataset is untyped you need to access the table in a fashion like
this:

Me.Ds.Tables("Groups")

whereas when you create a typed dataset, the tables, columns and rows become
properties of the DataSet and you can access them like this:

Me.ds.Groups

This syntax would not work with an untyped DataSet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top