简体   繁体   中英

How can I add one row to a DataGridView?

I work with a WinForms app. I want to add one row to a DataGridView that this row must enter to database. What event handler must I use to do this?

Is your DataGridView bound to that database? 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.

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 .

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

If the DataGridView isn't bound to the database, try to bound it or write the data to the database programmatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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