How to add a new row to datagridview programmatically

前端 未结 18 1757
滥情空心
滥情空心 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:47

    here is another way to do such

     private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView1.ColumnCount = 3;
    
            dataGridView1.Columns[0].Name = "Name";
            dataGridView1.Columns[1].Name = "Age";
            dataGridView1.Columns[2].Name = "City";
    
            dataGridView1.Rows.Add("kathir", "25", "salem");
            dataGridView1.Rows.Add("vino", "24", "attur");
            dataGridView1.Rows.Add("maruthi", "26", "dharmapuri");
            dataGridView1.Rows.Add("arun", "27", "chennai"); 
        }
    

提交回复
热议问题