如何从windows应用程序c#中的datagridview中删除数据 [英] how to delete data from datagridview in windows application c#
本文介绍了如何从windows应用程序c#中的datagridview中删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在windows应用程序中删除datagridview中的数据c#
how to delete data from datagridview in windows application c#
推荐答案
第一个选项:
The first option:
myDataGridView.Rows.Clear()
第二个选项:
The second option:
//Here we have to check if we are bound to a data source
if (myDataGridView.DataSource != null)
{
myDataGridView.DataSource = null;
}
else
{
myDataGridView.Rows.Clear();
}
第三种选择:
The third option:
datatbl.Rows.Clear() // If DataGridView is bound to DataTable
myDataGridView.DataBind();
datagridview -in-wndows-form.html [ ^ ]
查看此链接..希望它会有所帮助..
datagridview-in-wndows-form.html[^]
Check this link..hope it will help..
这里showdata是我的datagridview名称
Here showdata is my datagridview name
First Fire CellClick Event of your datagridview
the use it
if (e.ColumnIndex == "ur button column index")
{
if (DialogResult.Yes == MessageBox.Show("Are you sure You Want to delete?",MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
{
int ch = 0;
int id = ShowData.CurrentRow.Index;
int dd = convert.ToInt32(ShowData.Rows[id].Cells["ID"].Value.ToString());
string Delete = "Delete from ReceivePayment where ID=" + dd + "";
OleDbCommand cmd = new OleDbCommand(Delete, Ut.con);
Ut.con.Open();
int x = cmd.ExecuteNonQuery();
Ut.con.Close();
if (x != 0)
{
MessageBox.Show("data delete seccesfully ", ,MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
}
}
}
选择答案.....
select as answer.....
这篇关于如何从windows应用程序c#中的datagridview中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文