tags:

views:

1180

answers:

1

listbox1.items[0].tostring();

its the command for getting the text value of item at 0th index but i have some list boxes in my form which are data bound to a sql database table.When ever i use this command it gives me (System.Data.DataRowView) as a string as output regardless of the actual text value of the listbox item at 0th index.Plz guide

+2  A: 

You can use the Text property of the ListItem:

string itemText = ListBox1.Items[0].Text;

Update: If you're in WinForms, a bound list box will return a DataRowView:

DataRowView drv = (DataRowView)ListBox1.Items[0];
string itemText = drv.Row["MyColumn"].ToString();
CMS
are you sure this thing works because its not available in the pop up solutions panel when we type the commands
Mobin
That was quite helpful dear but i had to make some changes to it with the commandstring itemtext = drv.item["Column"].tostring();instead i used string row2 = drv.Row["Time_End"].ToString();
Mobin
Thanks now updated, I'm away from my development machine, I haven't actually tested it.
CMS