编辑数据视图中的行
本文关键字:视图 数据 编辑 | 更新日期: 2023-09-27 17:49:27
早上好,我想知道如何编辑数据视图中的行。例如,一个包含3列的datagridview,其中第1列和第3列已经填充(有数据),而第2列不包含数据,因为我填充该列时保留了其他列中的数据。
data 'm没有捕获任何数据库。我是通过一个数据表来做的。
Column 1 Column 2 Column 3
xxxxx xxxxx
xxxxx xxxxx
xxxxx xxxxx
dataGridView这个好,因为我做填充列2 ?
DataTable mytable = new DataTable ( " Class Name ");
mitabla.Columns.Add (new DataColumn ( " Class Name " , typeof (string ))) ;
mitabla.Columns.Add (new DataColumn ("# Method " , typeof (string ))) ;
mitabla.Columns.Add (new DataColumn ("# lines " , typeof (int ))) ;
DataGridView1.DataSource = mytable ;
我假设你正在使用WinForms,因为你引用了DataGridView。
你真的只需要在你的数据表中有一些行。我假设您有一些循环来填充这些行,如下所示。
private void Form1_Load(object sender, EventArgs e)
{
DataTable mytable = new DataTable(" Class Name ");
mytable.Columns.Add(new DataColumn(" Class Name ", typeof(string)));
mytable.Columns.Add(new DataColumn("# Method ", typeof(string)));
mytable.Columns.Add(new DataColumn("# lines ", typeof(int)));
// Use your own logic to fill the table with data
for (int i = 0; i < 10; i++)
{
DataRow dr = mytable.NewRow();
dr[" Class Name "] = "class" + i;
dr["# Method "] = "";
dr["# lines "] = i;
mytable.Rows.Add(dr);
}
dataGridView1.DataSource = mytable;
}