How to get text value from list index in c #

ListBox1.Items [0] .ToString ();

its a command to get the text value of an element at the 0th index, but I have some list fields in my form that are bound to the sql database table. When I use this command, it gives me (System.Data.DataRowView) as a string as an output regardless of the actual text value of the list item in the 0th pointer .Plz guide

+3
source share
2 answers

You can use the Text property for ListItem:

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

Update:  If you are in WinForms, the linked list will return a DataRowView:

DataRowView drv = (DataRowView)ListBox1.Items[0];
string itemText = drv.Row["MyColumn"].ToString();
+3
source

.Text no longer working from 07/23/2013

Use ListBox1.Items[index].ToString();

+2

Source: https://habr.com/ru/post/1703992/


All Articles