views:

91

answers:

2

i bound the list box with data table.display member is "Code" and value member is "ID".no w i want to retrieve the all item of list box.but it return me system.data.datarow.how can i get all item from ListBox in this Case

A: 

You can use the DataRow object to get the values of Code and ID columns:

foreach(var dr in ListBox1.Items)
{
    var code = dr["Code"];
    var id = dr["ID"];
}
TheVillageIdiot
A: 
foreach (object objObject in listBox1.Items)
            {
                System.Data.DataRowView objDataRowView = (DataRowView)objObject;
                if (!(objDataRowView["Column_Name"].ToString() == "Search String")
                {
                    Aray[i++]=objDataRowView["Column_Name"].ToString();
                }                    
            }

if Aray is a collection or Array of strings then it will have all the items of your search criteria in it or if you want to remove condition just remove if condition :D

Mobin