如可禁止DataGrid (windows)中Delete键 把DataGrid 的readonly属性设置为true 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 同意楼上的,改ReadOnly属性。 把DataGrid 的readonly属性设置为true 改這有什么用﹐人家肯定是要修改的﹐只是禁止鍵而已試一下先捕獲鍵﹐然后E.CANCEL=TRUE; 最简单的方法,你在后台不写delete函数的内容,点击不就没有任何执行吗,啊哈哈 用KeyPress事件把delete屏蔽掉就OK了 private void dgTasks_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { ShowTaskFormFromDataGrid(); } else if (e.KeyCode == Keys.Delete) { DialogResult mbResult = MessageBox.Show(m_ResourceManager.GetString("Are_you_sure_you_want_to_delete"), m_ResourceManager.GetString("Confirm_Task_Delete"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); this.Refresh(); if (mbResult == DialogResult.Yes) { int taskID = GetSelectedTaskID(); DataRow dr = m_DataLayer.DsTasks.Tasks.Rows.Find(taskID); if (dr != null) dr["IsDeleted"] = true; UpdateTasks(); } } } 可以用系统检测到按DELETE键时,将它禁用,离开DELETE时开放DELETE键或者写空代码来禁用DELETE键 Key_down 根本不会触发就删除了 不要在dataGrid里面写删除的代码,另外写一个方法,当点删除按钮以后获取当前行的记录号,然后调用你写的删除方法 我说的删除按钮不是dataGrid里的删除按钮,是单独的一个按钮 dataGrid1.DataSource=dataTable1;dataTable1.DefaultView.AllowDelete=false; DataGrid1.Columns[0].Visible =false;将按钮列屏蔽,Columns[]中的数字为按钮列在datagrid中的列数仅供参考。 datagrid的经典问题了,经常有人问,看: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?http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q889q DG.DataSource=dv;dv.AllowDelete=false; 如何加private void dgTasks_KeyDown这个事件呢?在private void InitializeComponent() {this.dgTasks.KeyDown += new System.Windows.Forms.KeyPressEventHandler(this.dgTasks_KeyDown);}中把事件加近来总是说类型不一样的错 如何取用户控件里的某个属性值? 启动程序时如何同时打开多个窗口? 关于XML 读取问题 web开发中,为什么在类中没有Server对象呀 请教一条SQL语句... 如何使客户去绘制的图像在Refresh()没有闪烁效果! 请问在哪里才可以得到C#的参考手册? ??为什幺我下的SDK里没有C#的编译器?? 我的C#在创建Web应用程序时出现错误报告,帮帮忙 我是个初学者,请指教 水晶报表输出到一个流,提示无效的输出选项? 在C#中如何把word的doc文件转换为html文件?
試一下先捕獲鍵﹐然后E.CANCEL=TRUE;
{
if (e.KeyCode == Keys.Enter)
{
ShowTaskFormFromDataGrid();
}
else if (e.KeyCode == Keys.Delete)
{
DialogResult mbResult = MessageBox.Show(m_ResourceManager.GetString("Are_you_sure_you_want_to_delete"), m_ResourceManager.GetString("Confirm_Task_Delete"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
this.Refresh(); if (mbResult == DialogResult.Yes)
{
int taskID = GetSelectedTaskID();
DataRow dr = m_DataLayer.DsTasks.Tasks.Rows.Find(taskID); if (dr != null)
dr["IsDeleted"] = true; UpdateTasks();
}
}
}
或者写空代码来禁用DELETE键
dataTable1.DefaultView.AllowDelete=false;
将按钮列屏蔽,Columns[]中的数字为按钮列在datagrid中的列数
仅供参考。
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?
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q889q
dv.AllowDelete=false;
在
private void InitializeComponent()
{
this.dgTasks.KeyDown += new System.Windows.Forms.KeyPressEventHandler(this.dgTasks_KeyDown);
}中把事件加近来总是说类型不一样的错