views:

18

answers:

2

Hi,

When i render contextmenustrip, it gets render at the top left of my PC Screen. I have a listview, which contains 5-6 items and on right click of each item, the context Menu strip gets displayed.Also i need to change the color of context menu strip including backgrounds and text as well.

Thanks in advance!

A: 

You haven't shown any code, but if you're not calling the Show overload that takes a control as a parameter, the new Point(0, 0) that your obviously passing will put the menu in the upper left of the screen.

Matthew Ferreira
Thanks for reply.Yes thats what it happens. I have just Written ContextMenu1.Show(). What should i write to make sure that it is shown below each listview selected items?
Romil Nagrani
Look at some of the overloads for Show. One of them takes a Control and a Point. Pass your ListView as the control, and the (x,y) coordinates of the item you want to show near. You can request those coordinates from the ListView for any item it displays.
Matthew Ferreira
+1  A: 

By far the simplest way is to just set the ListView.ContextMenuStrip property to your CMS, everything is automatic then. You can do so in the designer.

If you need a custom handler for some reason, to check if the right item was clicked for example, then you can call the Show() method property with code like this:

    private void listView1_MouseClick(object sender, MouseEventArgs e) {
        if (allowContextMenu(listView1.SelectedItems) {
            contextMenuStrip1.Show(listView1, e.Location);
        }
    }
Hans Passant