这个MS简单的问题,把我搞迷糊了,具体表现是:
1.ListView没有ContextMenuStripNeeded事件,所以不能在这个事件中动态判断加载不同的菜单。
2.ListView的MouseClick事件对右击列标题完全没有反应,所以连判断鼠标单击的坐标这条路也跟我堵死了。
3.ListView的ColumnClick事件只对左键有反应。郁闷..., 放100分,先出去吃饭...

解决方案 »

  1.   

    首先在Form中加一个contextMenuStrip控件,编辑控件的菜单项目,后:        private void listView1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {                String str = listView1.SelectedItems[0].Text;
                    Point p = new Point (e.X,e.Y );
                    contextMenuStrip1.Show(listView1, p);
                }
            }
      

  2.   

    楼主参考下:
    //右键菜单
            private void lvFileInfo_MouseUp(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    ListViewItem lvi = lvFileInfo.GetItemAt(e.X, e.Y);
                    if (lvi == null)
                    {
                        //显示菜单
                    }
                    else
                    {
                        //显示菜单
                    }
                }
            }
      

  3.   

    1楼的可能还没看清我的意思。况且,添加右键菜单没有你说的这么麻烦。
    2楼的试过没有,MouseUp事件同样不会在右击列标题时发生。
      

  4.   

    LZ把:private void listView1_MouseClick(object sender, ColumnClickEventArgs e)
    改为:
    private void listView1_MouseClick(object sender, MouseEventArgs e)试试
    listView1的MouseClick参数可以重载?
    为ListView设置鼠标右键选中事件。经常需要在右键选中某项时弹出浮动菜单用到。
    首先为ListView控件添加MouseClick的Event,然后下面代码:
            private void listView1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    String str = listView1.SelectedItems[0].text;
                    MessageBox.Show(str);
                }
            }
    代码显示了鼠标右键当前选中的项。很多人问怎么获得ListView中选择项的内容,上面就是方法。
    禁止ListView中进行多项选中(禁用多选)
                listView1.MultiSelect = false;
    给ListView在鼠标右键选中的情况下添加浮动菜单:
    首先在Form中拽一个contextMenuStrip控件,编辑控件的菜单项目,然后:        private void listView1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {                String str = listView1.SelectedItems[0].Text;
                    Point p = new Point (e.X,e.Y );
                    contextMenuStrip1.Show(listView1, p);
                }
            }
      

  5.   

    ListView的ColumnHeader是很锉。
    可以利用listView1.ContextMenuStrip 属性,这个属性指定菜单1,在右击列标题、内容区、空白区,都会弹出。
    然后,需要做的就是,在右击内容区的时候,换个菜单2。当菜单2关闭后,再把listView1.ContextMenuStrip 设置回菜单1。
    如果需要控制空白区弹出的菜单,就使用MouseUp事件。
    public Form1()
            {
                InitializeComponent();
                listView1.ContextMenuStrip = contextMenuStrip1;
                
                contextMenuStrip2.Closed += new ToolStripDropDownClosedEventHandler(contextMenuStrip2_Closed);
            }        void contextMenuStrip2_Closed(object sender, ToolStripDropDownClosedEventArgs e)
            {
                listView1.ContextMenuStrip = contextMenuStrip1;
            }        private void listView1_MouseClick(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    listView1.ContextMenuStrip = null;
                    contextMenuStrip2.Show(listView1, e.Location);
                    System.Console.WriteLine("right clicked");
                }
            }