How to programmatically add a row to a datagridview when it is data-bound?

后端 未结 4 624
别跟我提以往
别跟我提以往 2020-12-20 15:56

How can I add a row to a datagridview control if it is bounded to a datasource (datatable) ? Thanks!

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-20 17:01

    Add a row to the datatable, the datagridview will update automatically:

    DataTable dt = myDataGridView.DataSource as DataTable;
    //Create the new row
    DataRow row = dt.NewRow();
    
    //Populate the row with data
    
    //Add the row to data table
    dt.Rows.Add(row);
    

提交回复
热议问题