title: Data from datatable only populating one column in ListView with C# Winforms
body: <p>I have a datatable that I have populated from an Access database that has table name, "codes" and 3 columns, "CodeNum", "TableName" and "Desc". In my Winforms C# app, I would like to populate a ListView with this datatable and have it show columns(with column names) in same format. I have tried numerous code combinations, but cannot get this to work. The code below shows CodeNum and TableName data in 1st column, not DESC data and does not show column name(CodeNum). Any help greatly appreciated. Don't really need, 
  "DataRowState.Deleted" if statement but works same way when it is commented out.</p>
  
  <p>Listview should have 3 columns with data listed in each column.</p>
  
  <p>Thank you.</p>
  
  <pre><code>        //Get data from Access database and populate datatable "dt"
          OleDbConnection Conn = new OleDbConnection();
          string conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=M:\gendoc\Codes.mdb;Persist Security Info=False;";
          ListViewItem LItem1 = new ListViewItem();
          Conn.ConnectionString = conn;
          Conn.Open();
  
          DataTable dt = new DataTable();
          DataSet ds = new DataSet();
          ds.Tables.Add(dt);
          OleDbDataAdapter da = new OleDbDataAdapter("select * from Codes order by CodeNum", Conn);
          da.Fill(dt);
          Conn.Close();
  
  
          // Clear the ListView control
          listView1.Items.Clear();
          int ColCount = dt.Columns.Count;
          //Add columns
          for (int k = 0; k &lt; ColCount; k++)
          {
              listView1.Columns.Add(dt.Columns[k].ColumnName);
          }
          // Display items in the ListView control
          for (int i = 0; i &lt; dt.Rows.Count; i++)
          {
              DataRow drow = dt.Rows[i];
  
              // Only row that have not been deleted
              if (drow.RowState != DataRowState.Deleted)
              {
                  // Define the list items
                  ListViewItem lvi = new ListViewItem(drow[0].ToString());
                  for (int j = 1; j &lt; ColCount; j++)
                  {
                      string g = drow[j].ToString();
                      lvi.SubItems.Add(drow[j].ToString());
                  }
                  // Add the list items to the ListView
                  listView1.Items.Add(lvi);
              }
          }
  </code></pre>