Adding rows on datagridview manually

后端 未结 2 1721
眼角桃花
眼角桃花 2021-01-18 05:18

I\'ve inserted a checkbox column and textbox column on the datagridview. how can add rows manually on the textbox column.

It should be like this:

che         


        
2条回答
  •  温柔的废话
    2021-01-18 05:30

    You can use the Rows collection to manually populate a DataGridView control instead of binding it to a data source.

    this.dataGridView1.Rows.Add("five", "six", "seven", "eight");
    this.dataGridView1.Rows.Insert(0, "one", "two", "three", "four");
    

    Take a look at the documentation

    And you can do something like this too:

    DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[0].Clone();
    row.Cells["Column2"].Value = "XYZ";
    row.Cells["Column6"].Value = 50.2;
    yourDataGridView.Rows.Add(row);
    

    See this answer

提交回复
热议问题