Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

populate a listview or listbox from datatable (windows form)

I am trying to populate a listview or a listbox from database using C#. I am using datatable to grab data. I am using this code below. But listview or the listbox is populating something like "System.Data.DataRow" text. Where I have something else in my database. Pls Help

query = "select itemtag from tbl_inventory order by itemtag";
DataTable dt = con.DataTable(query);
int count = dt.Rows.Count;
if (count >0)
{
    //listView1.Items.Clear();
    listBox1.Items.Clear();

    for (int i = 0; i < count; i++)
    {
        //listView1.Items.Add(dt);
        listBox1.Items.Add(dt.Rows[i].ToString());
    }
}

As you see I am getting output like "System.Data.DataRow",where I have something else in my database

Any help?

like image 516
Bappy Avatar asked Feb 22 '14 04:02

Bappy


1 Answers

If your using a listbox then directly use the DATASOURCE property...

ListBox1.DataSource 
  1. Link1
  2. Link2
  3. Link3
like image 101
andy Avatar answered Oct 12 '22 08:10

andy