日期:2014-05-18  浏览次数:20837 次

50分关于datagird的问题
winform     用button删除选中的datagird中这一行
用正确的代码砸死我吧

------解决方案--------------------
可以删除数据库中该记录的然后重新绑定
或者删除dt中的改行,重新邦定


------解决方案--------------------
首先在DataGrid中添加一个CheckBox然后找到哪个CheckBox被选择了,通过CheckBox的值找到删除行的ID,最后删除记录。
如果你不会代码的话,去查吧
------解决方案--------------------
DataGridView.SelectRows[0];
------解决方案--------------------
dataGridView1.Rows.Remove(dataGridView1.Rows[e.RowIndex]);
------解决方案--------------------
private void buttondel_Click(object sender, EventArgs e)
{
/*delete*/
if (dataset.Tables[ "table1 "].Rows.Count > 0 )
{
if (dataGridView1.CurrentRow.Index > = 0)
{
if (dataset.Tables[ "table1 "].Rows[dataGridView1.CurrentRow.Index].RowState != DataRowState.Detached &&
dataset.Tables[ "table1 "].Rows[dataGridView1.CurrentRow.Index].RowState != DataRowState.Added)
{
dataset.Tables[ "table1 "].Rows[dataGridView1.CurrentRow.Index].Delete();
}
else if (dataset.Tables[ "table1 "].Rows[dataGridView1.CurrentRow.Index].RowState == DataRowState.Added)
{
dataGridView1.Rows.Remove(dataGridView1.CurrentRow);
}


}
}


}