简体   繁体   English

如何将一行添加到DataGridView?

[英]How can I add one row to a DataGridView?

I work with a WinForms app. 我使用WinForms应用程序。 I want to add one row to a DataGridView that this row must enter to database. 我想向DataGridView添加一行,该行必须输入到数据库中。 What event handler must I use to do this? 我必须使用哪个事件处理程序来执行此操作?

Is your DataGridView bound to that database? 您的DataGridView是否绑定到该数据库? If so, you should be adding and deleting rows in that data source, not in the grid control itself. 如果是这样,则应该在该数据源中而不是在网格控件本身中添加和删除行。 Try calling the AddNew method on the binding source. 尝试在绑定源上调用AddNew方法

If you're using a standalone DataGridView that isn't bound to a database, then you can call one of the many overloads of the Add method of the grid control's Rows collection . 如果使用未绑定到数据库的独立DataGridView ,则可以调用网格控件的Rows集合Add方法的许多重载之一。

This might help you out to add a row to the DataGridView: http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview%28v=vs.80%29.aspx 这可能会帮助您向DataGridView添加一行: http : //msdn.microsoft.com/de-de/library/system.windows.forms.datagridview%28v=vs.80%29.aspx

If the DataGridView isn't bound to the database, try to bound it or write the data to the database programmatically. 如果DataGridView未绑定到数据库,请尝试将其绑定或以编程方式将数据写入数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM