Winform下DataGrid如何屏蔽Delete按键?

howbigsea 2003-04-09 12:57:53

DataGrid选中1行,按delete删除,如何屏蔽,不让删除?
...全文
76 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cqnimin 2003-04-09
  • 打赏
  • 举报
回复
up:)
howbigsea 2003-04-09
  • 打赏
  • 举报
回复
this.dataGrid1.SetDataBinding(dsProduct,"c_quotations");
this.button_getbmem.Focus();
//限制另外增加的新行
CurrencyManager cm = (CurrencyManager)BindingContext[this.dataGrid1.DataSource,this.dataGrid1.DataMember];
DataView dv = (DataView) cm.List;
dv.AllowNew = false;
dv.AllowDelete=false;
howbigsea 2003-04-09
  • 打赏
  • 举报
回复
5.54 How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key?

You can handle this by subclassing your grid and overriding either PreProcessMessage or ProcessDialogKey. The code below assumes your datasource is a dataview. If it is not, you could just remove that check

[C#]

public override bool PreProcessMessage( ref Message msg )

{

Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;

if(msg.Msg == WM_KEYDOWN

&& keyCode == Keys.Delete

&& ((DataView) this.DataSource).AllowDelete)

{

if(MessageBox.Show("Delete this row?", "", MessageBoxButtons.YesNo) == DialogResult.No)

return true;

}

return base.PreProcessMessage(ref msg);

}



解决了
呵呵
谁先来给谁分!

110,524

社区成员

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

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

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