c# - ListBoxes using same context menu with different items, On ListBox Click event -


i have 3 listboxes , on mousedown event want them show same context menu there items differ on every different listbox click. example:

- contextmenu when clicked on :listbox1      *  should show: {edit,add items} - contextmenu when clicked on :listbox2     *  should show: {remove, add price} - contextmenu when clicked on :listbox3     *  should show: {something, remove} 

following code using listbox1:

    private void mousedown(object sender, mouseeventargs e)     {         if (e.button == mousebuttons.right)         {             listbx_1.selectedindex = listbx_1.indexfrompoint(e.location);             if (listbx_1.selectedindex != -1)             {                 listboxcontextmenu_opening();             }         }     }      private void listboxcontextmenu_opening()     {         listboxcontextmenu.items.clear();         listboxcontextmenu.items.add("edit");         listboxcontextmenu.items.add("add items");     } 

now want listbox2 , listbox3 context menu(same menu 3 listboxes) items added using mousedown event , how achieve that? suggestions welcomed!!

it better create 3 separate listbox contextmenus. way won't need watch mousedown.

but can achieve dynamically editing contextmenu on mousedown.

create contextmenu items , have following in mousedown. assign mousedown events mousedown.

private void mousedown(object sender, mouseeventargs e) {     listbox l = (listbox) sender;     if (e.button == mousebuttons.right)     {         l.selectedindex = l.indexfrompoint(e.location);         if (l.selectedindex != -1)         {             if (l.name == "listbox1")             {                 listboxcontextmenu.items.clear();                 listboxcontextmenu.items.add("edit");                 listboxcontextmenu.items.add("add items");             }             else if(l.name = "listbox2")//etc         }     } } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -