如何删除选定的DataGridViewRow和更新连接的数据库表? [英] How to delete a selected DataGridViewRow and update a connected database table?
本文介绍了如何删除选定的DataGridViewRow和更新连接的数据库表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows上 DataGridView的
控制窗体应用程序(用C#编写)。
I have a DataGridView
control on a Windows Forms application (written with C#).
我需要的是:当用户选择一个的DataGridViewRow,然后点击一个删除按钮,则该行应删除和下一步,数据库需要使用表适配器进行更新。
What I need is: when a user selects a DataGridViewRow, and then clicks on a 'Delete' button, the row should be deleted and next, the database needs to be updated using table adapters.
这是我迄今为止:
private void btnDelete_Click(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedRows.Count > 0)
{
dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
}
}
此外,这只是删除一行。我想它,用户可以选择多行。
Furthermore, this only deletes one row. I would like it where the user can select multiple rows.
推荐答案
这code将删除选定的项目 dataGridView1
:
This code removes selected items of dataGridView1
:
private void btnDelete_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in this.dataGridView1.SelectedRows)
{
dataGridView1.Rows.RemoveAt(item.Index);
}
}
这篇关于如何删除选定的DataGridViewRow和更新连接的数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文