Reputation: 1
Hello i have got an problem i need to show the contents of an database table the name is Employees.
it needs to get shown in an list view or something simular.
i cant get the listview box to show the table contents.
Upvotes: 0
Views: 137
Reputation: 1219
I think following code should work for you:
private void BindTable(DataTable table)
{
lvItemList.Clear();
foreach (DataRow row in table.Rows)
{
ListViewItem lvItem = new ListViewItem();
lvItem.Text = row["ColumnName"].ToString();
lvItemList.Items.Add(lvItem);
// Or in a one-liner
//lvItemList.Items.Add(row["ColumnName"].ToString();
}
}
Upvotes: 3
Reputation: 9578
You need to override the toString() method and provide the string data you want to display.
Upvotes: 0