C implements a method for reading DataSet data and displaying it in an ListView control

  • 2021-08-12 03:20:10
  • OfStack

This article illustrates how C # implements reading DataSet data and displaying it in an ListView control. Share it for your reference. The details are as follows:


/*lvStudentList For ListView Control name  */   
DataSet ds = new DataSet();
ds = student.QueryStudents(); // Query the information of the table 
int rowCount, columnCount,i,j;
rowCount = ds.Tables[0].Rows.Count;
columnCount = ds.Tables[0].Columns.Count;
lvStudentList.BeginUpdate();
lvStudentList.Items.Clear();
string[] lvitem = new string[columnCount];
for (i = 0; i < rowCount; i++)
{
  for (j = 0; j < columnCount; j++)
  {
   lvitem[j] = ds.Tables[0].Rows[i][j].ToString();
  }
  ListViewItem lvi = new ListViewItem(lvitem);
  lvStudentList.Items.Add(lvi);
}
lvStudentList.EndUpdate();

I hope this article is helpful to everyone's C # programming.


Related articles: