D
David Gouge
Hi All,
Hope someone can point me in the right direction.
Doing a very simple app in C# .net 2.0 where i have a listbox bound to a
datatable (StaffTable) with the DisplayMember being the name field and
the ValueMember being the number field. I have the following code in
the form's constructor:
StaffList.DataSource = StaffTable;
StaffList.DisplayMember = "name";
StaffList.ValueMember = "number";
What i need to do is grab the data from the ValueMember field for the
selected ListBox item. So far i have only found the following way to do
this:
DataRowView aDrv = (DataRowView)StaffList.SelectedItem;
string number = aDrv.Row[2].ToString().Trim();
....which seems a bit of a long way round.
In .net 1.1, all i had to do was:
string number = StaffList.Items[StaffList.SelectedIndex].Value
....but this does not build in 2.0.
So, is the way i'm doing it the only way in 2.0 or is there are more
elegant way as in my 1.1 code?
Thanks in advance.
Hope someone can point me in the right direction.
Doing a very simple app in C# .net 2.0 where i have a listbox bound to a
datatable (StaffTable) with the DisplayMember being the name field and
the ValueMember being the number field. I have the following code in
the form's constructor:
StaffList.DataSource = StaffTable;
StaffList.DisplayMember = "name";
StaffList.ValueMember = "number";
What i need to do is grab the data from the ValueMember field for the
selected ListBox item. So far i have only found the following way to do
this:
DataRowView aDrv = (DataRowView)StaffList.SelectedItem;
string number = aDrv.Row[2].ToString().Trim();
....which seems a bit of a long way round.
In .net 1.1, all i had to do was:
string number = StaffList.Items[StaffList.SelectedIndex].Value
....but this does not build in 2.0.
So, is the way i'm doing it the only way in 2.0 or is there are more
elegant way as in my 1.1 code?
Thanks in advance.