How to add a new row to datagridview programmatically

前端 未结 18 2140
滥情空心
滥情空心 2020-11-22 09:40

if add row to DataTable

DataRow row = datatable1.NewRow();
row[\"column2\"]=\"column2\";
row[\"column6\"]=\"column6\";
datatable1.Rows.Add(row);         


        
18条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 09:49

    Like this:

     dataGridView1.Columns[0].Name = "column2";
     dataGridView1.Columns[1].Name = "column6";
    
     string[] row1 = new string[] { "column2 value", "column6 value" };
     dataGridView1.Rows.Add(row1);
    

    Or you need to set there values individually use the propery .Rows(), like this:

     dataGridView1.Rows[1].Cells[0].Value = "cell value";
    

提交回复
热议问题