禁用的DataGridView系统的ContextMenu [英] Disable DataGridView System ContextMenu
问题描述
有谁知道我可以禁用系统的上下文菜单,当用户在DataGridViewTextBoxCell右点击?我试图重写WndProc在DataGridView的水平(没有的WndProc覆盖在细胞水平上),但似乎没有任何工作。任何帮助将大大AP preciated。
下面是我用在一个普通的文本框来实现这一点,但是,我需要工作以同样的方式为DataGridViewCell的?
公共类NoContextTextBox:文本框{
私人静态只读INT WM_CONTEXTMENU = 123;
保护覆盖无效的WndProc(参考消息M){
如果(m.Msg!= WM_CONTEXTMENU){
base.WndProc(REF米);
}
}
}
这为我工作:
私人无效dataGridView1_EditingControlShowing(对象发件人,DataGridViewEditingControlShowingEventArgs E)
{
e.Control.ContextMenu =新的ContextMenu();
}
只要设置ContextMenu属性为新的(空)的ContextMenu在DataGridView的EditingControlShowing事件。
Does anyone know how I can disable the System Context Menu when a user right clicks in a DataGridViewTextBoxCell? I have tried to override the WndProc at the DataGridView level (as there is no WndProc to override on the Cell level), but nothing seems to work. Any help would be greatly appreciated.
The following is what I use to achieve this in a regular TextBox, however, I need to work the same way for a DataGridViewCell?
public class NoContextTextBox : TextBox {
private static readonly int WM_CONTEXTMENU = 123;
protected override void WndProc(ref Message m) {
if (m.Msg != WM_CONTEXTMENU) {
base.WndProc(ref m);
}
}
}
This worked for me:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.ContextMenu = new ContextMenu();
}
Just set the ContextMenu property to new (empty) ContextMenu in the EditingControlShowing event of the DataGridView.
这篇关于禁用的DataGridView系统的ContextMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!