I
Irwin M. Fletcher
ListBox DataSource DisplayMember Property
Problems in C#
I have a (single select) listbox with data and
when I click on the list I can't get the right
text selected.
My listbox is setup using the DataSource property.
I set my ValueMember and DisplayMember
listBox1.ValueMember = "TypeID";
listBox1.DisplayMember = "Name";
I am able to get the "TypeID" (ValueMember) when I click on
the items.
I do that like this...
int intTest;
intTest = System.Int32.Parse(listBox1.SelectedValue.ToString());
But I can't get the text (DisplayMember).
I have used these two ways, but...
string strDispMem;
strDispMem = listBox1.Items[index].ToString();
// the above returns... "System.Data.DataRowView"
or
strDispMem = listBox1.Text;
// The above repeats first selection the user clicks on.
Any ideas???
Thanks... Irwin
Problems in C#
I have a (single select) listbox with data and
when I click on the list I can't get the right
text selected.
My listbox is setup using the DataSource property.
I set my ValueMember and DisplayMember
listBox1.ValueMember = "TypeID";
listBox1.DisplayMember = "Name";
I am able to get the "TypeID" (ValueMember) when I click on
the items.
I do that like this...
int intTest;
intTest = System.Int32.Parse(listBox1.SelectedValue.ToString());
But I can't get the text (DisplayMember).
I have used these two ways, but...
string strDispMem;
strDispMem = listBox1.Items[index].ToString();
// the above returns... "System.Data.DataRowView"
or
strDispMem = listBox1.Text;
// The above repeats first selection the user clicks on.
Any ideas???
Thanks... Irwin