DataTable To ListView

public static void DataTablToListView(DataTable dt, ListView lst)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
lst.Columns.Add(dt.Columns[j].ColumnName);
}

for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
string[] rowdata = new string[dt.Columns.Count];
for (int j = 0; j < dt.Columns.Count; j++)
{
rowdata[j] = dr[j].ToString();
}


ListViewItem lvi = new ListViewItem(rowdata);
lst.Items.Add(lvi);
}
}
 

Sandeep

a dev, an amateur photographer and a father

 

One thought on “DataTable To ListView

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: