c# - toolstripmenuitem subitem - double entries -


i trying add event handler dropdownitems of toolstrip. when add event handler, each time event triggered, dropdownitems duplicated.

my toolstrip menu items projects, , each project can have multiple tasks. when user clicks on task, event handler triggered, has method starts track time. creates new menu item stop timer.

how can configure code prevent duplicate items?

thanks in advance, jason

private void setupmenu() {     ctxmainmenu.items.clear();      //ctxmainmenu.refresh();     _workitemvalid = false;      toolstripmenuitem newmenu = null;      if (_currentworkitemid > 0)     {         newmenu = new toolstripmenuitem("stop working on workitem:" + _currentworkitemid);         ctxmainmenu.items.add(newmenu);         ctxmainmenu.refresh();     }      try     {         //ctxmainmenu.refresh();         foreach (string projectname in checkedprojects.items)         {              newmenu = new toolstripmenuitem(projectname);             //clear menu before building new 1             newmenu.dropdown.items.clear();             ctxmainmenu.refresh();             newmenu.dropdownitems.addrange(getworkitemmenuesforproject(projectname));             //newmenu.dropdownitemclicked += new toolstripitemclickedeventhandler(newmenuitem_dropdownitemclicked);             ctxmainmenu.items.insert(0, newmenu);          }     }     catch     {     } }  private void newmenuitem_dropdownitemclicked(object sender, toolstripitemclickedeventargs e) {     try     {         if (e.clickeditem.text.contains("stop working"))         {             stopwork();         }         else         {             if (_currentworkitemid > 0)             {                 switchtoworkitemto(int.parse(e.clickeditem.text.split(':')[0].tostring()));             }             else             {                 _currentworkitemid = int.parse(e.clickeditem.text.split(':')[0].tostring());                 startwork(_currentworkitemid);             }         }         ctxmainmenu.refresh();     }     catch { } } 


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -