且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从windows应用程序c#中的datagridview中删除数据

更新时间:2023-10-19 18:39:28

第一个选项:

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.....