C#中用到了ListView控件,我想选中其中一个Item,然后按键盘上下,完成自己的事件,但是不希望在listview当中selectitem也随着键盘的上下键而发生变化,即希望在listview中keydown代理中去掉系统的事件处理函数,只留下我自己的eventhandler,但是我不知道系统Eventhandler的名字,怎么处理呢?
我试了这样一段代码
Type t = listView.GetType();
PropertyInfo pi = t.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehl = (EventHandlerList)pi.GetValue(listView, null);
FieldInfo fieldInfo = (typeof(Control)).GetField("EventKeyDown", BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = ehl[fieldInfo.GetValue(null)];
if (d != null)
{
foreach (Delegate temp in d.GetInvocationList())
{
ehl.RemoveHandler(fieldInfo.GetValue(null), temp);
}
}但是每次d都是null
请各位支招,不胜感激
我试了这样一段代码
Type t = listView.GetType();
PropertyInfo pi = t.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehl = (EventHandlerList)pi.GetValue(listView, null);
FieldInfo fieldInfo = (typeof(Control)).GetField("EventKeyDown", BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = ehl[fieldInfo.GetValue(null)];
if (d != null)
{
foreach (Delegate temp in d.GetInvocationList())
{
ehl.RemoveHandler(fieldInfo.GetValue(null), temp);
}
}但是每次d都是null
请各位支招,不胜感激
这样keydown事件就不会继续传递了。 不知是否可行!