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
请各位支招,不胜感激

解决方案 »

  1.   

    这个好像不可行, 可以使用PreviewKeyDown事件, 处理完自己的代码后, 设置IsHandled = true
    这样keydown事件就不会继续传递了。 不知是否可行!
      

  2.   

    IsHandled是不是web中的,我的是form中的
      

  3.   

    那你为什么不用鼠标单击事件?要用selecteditem事件呢
      

  4.   

    不是selecteditem相关的问题,是先用鼠标选择一个item,此时该item为蓝色,即selectitem,但是我想对该item实现自己的键盘事件,每次按Up,item的蓝色也往上移动了一格,我现在只想让他相应我的事件,在后面不再执行系统UP的键盘事件,即选中的item始终不变