如何在数据绑定时以编程方式向datagridview添加一行? [英] How to programmatically add a row to a datagridview when it is data-bound?

查看:79
本文介绍了如何在数据绑定时以编程方式向datagridview添加一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果datagridview控件被绑定到数据源(datatable),我如何添加一行?谢谢!

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

推荐答案

向datatable添加一行,datagridview会自动更新:

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);

这篇关于如何在数据绑定时以编程方式向datagridview添加一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆