DisplayMember and ValueMember

adwaitjoshi

Active member
Joined
Dec 29, 2005
Messages
38
Programming Experience
1-3
While binding data for a listbox or combobox, we use the DisplayValue and DisplayMember method. Instead of specifying column names in the datatable, can I specify column indices?

For example is it possible to say

ListBox1.DisplayMember = 0
ListBox1.ValueMember = 1

instead of


ListBox1.DisplayMember = "Description"
ListBox1.ValueMember = "Code"
 
Moved to more appropriate forum. The VS.NET forum is for IDE-related issues.

The fact that both those properties are of type String should answer your question. You can use the index to get a DataColumn object from your DataTable and then use its ColumnName property, e.g.
VB.NET:
Expand Collapse Copy
ListBox1.DisplayMember = myTable.Columns(0).ColumnName
where myTable would be the table you just assigned to the DataSource.
 
Back
Top