在winform的datagrid中,怎样删除用户选择删除的那一行呢?

ttksj 2005-12-15 09:00:27
如题,谢谢!
...全文
174 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
marvelstack 2006-01-06
  • 打赏
  • 举报
回复
取出DataGrid当前行对应的DataTable的值。
如果DataGrid绑定的是DataView,
DataRowView drv = (DataRowView)this.BindingContext[this.ds,this.ds.Tables[0].TableName].Current;
//如果绑定的是DataTable
//DataRow dw = (DataRow)this.BindingContext[this.dataGrid1.DataSource,this.dataGrid1.Memeber].Current;
获取到drv就可以改数据,
DataRow dw = drv.Row; // 得到DataRow,
dw.Delete();//删除
solsolsol 2006-01-06
  • 打赏
  • 举报
回复
选中某一行
int curRow = dg1.CurrentCell.RowNumber;
string aaa = dg1[curRow,0].ToString();

string SQL = "delete from XXX where *** ='" + aaa + "'";
//.......
wwqna 2005-12-15
  • 打赏
  • 举报
回复
先获取datagrid的datakey再去数据库中删
之后再绑定一次
EverBluesoft 2005-12-15
  • 打赏
  • 举报
回复
int cntRow = this.dgOperatorSet.CurrentRowIndex ;/返回你选中的行号
this.dsOperatorSet.Tables[this.cmbZT.Text.Trim()].Rows[cntRow].Delete();//删除该行。

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧