Michel Boon
Michel Boon

Reputation: 1

Table content to list view

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

Answers (2)

mihirj
mihirj

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

One Man Crew
One Man Crew

Reputation: 9578

You need to override the toString() method and provide the string data you want to display.

Upvotes: 0

Related Questions