简体   繁体   English

如何在datagridview内部插入,更新,删除?

[英]How to insert, update, delete inside datagridview?

Hi guys I searched for lot on this topic but don't get any result. 嗨,我在这个主题上搜寻了很多东西,但是没有任何结果。 I want to know it is possible to add, update, delete inside datagridview in c# means i want to add new row and data inside the editable datagridview not from the forms control. 我想知道可以在C#中的datagridview中添加,更新,删除,这意味着我想在可编辑的datagridview中添加新行,而不是从表单控件中添加数据。 I want to place Add New, edit, delete button or anything inside datagridview. 我想在Datagridview中放置“添加”,“编辑”,“删除”按钮或其他任何内容。 In google there is lot of tutorials for this but from the form controls. 在谷歌上有很多关于这个的教程,但是来自表单控件。 This is possible in gridview control but i want to know this is also possible in datagridview or not If you have any link related to this then plz inform me. 这在gridview控件中是可能的,但是我想知道在datagridview中也可以,如果您有与此相关的任何链接,请告诉我。 Thanks in advance! 提前致谢!

You can Add new DataSet to your project, drag into it by DataSet Designer the table that you want edit with DataGridView by drag and drop from the Server Explorer to DataSet Designer, the runtime will create all the action to interact with you Dataset and TableAdapter, back into Form designer open Data Source Panel Drag your table under dataset to your Form .... done! 您可以将新的DataSet添加到您的项目中,由DataSet Designer将要使用DataGridView编辑的表从Server Explorer拖放到其中,运行时将创建所有与Dataset和TableAdapter进行交互的操作,回到“窗体设计器”中,打开“数据源”面板将数据集下的表拖到“窗体”中。

Next step it will call Update Method by single button here is the code: 下一步它将通过单个按钮调用更新方法,代码如下:

this.nameOfYourTableAdapter.Update(this.nameOfYourDataSet.nameOfYourTable);

ref: Microsoft MSDN 参考: Microsoft MSDN

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

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