如何在DataGridView中添加一行? [英] How can I add one row to a DataGridView?

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

问题描述

我正在使用WinForms应用程序。
我想向DataGridView添加一行,该行必须输入到数据库。
我必须使用什么事件处理程序?

解决方案

您的 DataGridView 绑定到该数据库?如果是这样,您应该在该数据源中添加和删除行,而不是在网格控件本身。尝试调用 AddNew 方法绑定源。



如果您使用独立的 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.

这篇关于如何在DataGridView中添加一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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