none
listview and contextMenu RRS feed

  • Question

  • I have a listView in details view and a contextMenu connected. I want the context menu to be displayed only when i right-click an item of list not when i right-click the list without an item selected.

    Thank You.

    Thursday, May 10, 2007 8:24 AM

Answers

  • donot not set the ListViews ContextMenuStrip before.

    show the contextMenu when MouseClick event occurs.

     

    ex:

    private void listView1_MouseClick(object sender, MouseEventArgs e) {

        if (e.Button == MouseButtons.Right) {

            contextMenuStrip1.Show(listView1, e.Location);

        }

    }

    Thursday, May 10, 2007 8:57 AM

All replies

  • donot not set the ListViews ContextMenuStrip before.

    show the contextMenu when MouseClick event occurs.

     

    ex:

    private void listView1_MouseClick(object sender, MouseEventArgs e) {

        if (e.Button == MouseButtons.Right) {

            contextMenuStrip1.Show(listView1, e.Location);

        }

    }

    Thursday, May 10, 2007 8:57 AM
  • Excellant answar!

     

    But I have some different problem. I am using small form like 200 by 200 pixel. It works file at the time of opening it. But if I change the location of the form, e.Location returns the location in respect of form. But contextMenuStrip showing it in respect of whole resolution. How to solve this problem ?

    In other words, how to get location in respect of whole screen resolution ?

    I thing that will solve the purpose

     

    Sudip Misra

    sudipmisra@hotmail.com

     

    Tuesday, November 18, 2008 11:43 AM
  • Answar:

    if (e.Button == MouseButtons.Right)
    {
      this.contextMenuStrip1.Show(e.Location.X + this.Left, e.Location.Y+this.Location.Y);
    }

    Monday, December 1, 2008 1:13 PM