Get value from listbox items
-
hi, i am using to retrive the value from listbox items as
foreach (var obj in listbox.Items)
{
?????????????????
}but i have no idea what should be in foreach body. thanks
-
hi, i am using to retrive the value from listbox items as
foreach (var obj in listbox.Items)
{
?????????????????
}but i have no idea what should be in foreach body. thanks
It depends what you want to do with the item. Unlike a
ListViewItem
, a list box item is just an object, whoseToString()
method is called to render its text in the list box. /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
hi, i am using to retrive the value from listbox items as
foreach (var obj in listbox.Items)
{
?????????????????
}but i have no idea what should be in foreach body. thanks
zeeShan, I hope this helps. It depends on what you want to do with your items. They are usually cast at some point. Consider this code. When something is selected in listBox1, it copies all of the contents into listBox2: private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { foreach (string item in listBox1.Items) { listBox2.Items.Add(item); } }
-
hi, i am using to retrive the value from listbox items as
foreach (var obj in listbox.Items)
{
?????????????????
}but i have no idea what should be in foreach body. thanks
Here i provide you source code wish that help you : for example if you want to calculate all values of liste item . Dim sum As Integer For Each item As String In data.ListBox1.Items sum += Double.Parse(item) Next textbox1.text = sum It will show total value of Items