DataTable To ListView

1:33 AM

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);
          }
      }

1 comments:

Post a Comment