c# - How to add a CellDoubleClick handler to a grid Automatically generated -
i creating multiple pages tab control
foreach (menus menu in allmenus) { tabpage toadd = new tabpage(); _productstabs.controls.add(toadd); toadd.text = menu.menu; toadd.backcolor = color.fromargb(39,39,39); }
for each tab create next add grid , fill data sql table
#region addgrids foreach (tabpage _tab in _productstabs.tabpages) { datagridview toadd = new datagridview(); toadd.size = new size(1390, 584); toadd.dock = dockstyle.fill; toadd.backgroundcolor = color.fromargb(39, 39, 39); toadd.defaultcellstyle.backcolor = color.fromargb(41, 41, 41); toadd.alternatingrowsdefaultcellstyle.backcolor = color.fromargb(49,49,49); toadd.gridcolor = color.fromargb(49, 49, 49); toadd.forecolor = color.white; toadd.rowheadersvisible = false; toadd.allowusertoresizerows = false; toadd.allowusertoaddrows = false; toadd.selectionmode = datagridviewselectionmode.fullrowselect; datagridviewtextboxcolumn _menu = new datagridviewtextboxcolumn(); _menu.headertext = "menu"; _menu.name = "_menucol"; _menu.readonly = true; datagridviewtextboxcolumn _name = new datagridviewtextboxcolumn(); _name.headertext = "name"; _name.name = "_namecol"; _name.readonly = true; datagridviewtextboxcolumn _desc = new datagridviewtextboxcolumn(); _desc.headertext = "description"; _desc.name = "_desccol"; _desc.width = 250; _desc.readonly = true; datagridviewtextboxcolumn _money = new datagridviewtextboxcolumn(); _money.headertext = "money"; _money.name = "_moneycol"; _money.readonly = true; _tab.controls.add(toadd); toadd.columns.addrange(new datagridviewcolumn[] { _menu, _name, _desc , _money }); #region sqlgeteverthing #region sqlgetallsubmenus string currsubmenu2 = "findid"; string menu = "findmenu"; ienumerable<submenus> results2; ienumerable<menus> curmenu; menus currmenu = new menus(); using (sqlconnection con = new sqlconnection("data source=vbss012;initial catalog=wintest_beta;integrated security=true")) { con.open(); curmenu = con.query<menus>(menu, new { menu = _tab.text }, commandtype: commandtype.storedprocedure); con.close(); } foreach (menus _menu in curmenu) { currmenu = _menu; } using (sqlconnection con = new sqlconnection("data source=vbss012;initial catalog=wintest_beta;integrated security=true")) { con.open(); results2 = con.query<submenus>(currsubmenu2, new { submenu = currmenu.id }, commandtype: commandtype.storedprocedure); currsubmenu = results2; con.close(); } #endregion #region fillgrid foreach (submenus _submenu in currsubmenu) { if (currmenu.id == _submenu.menuid) { toadd.rows.add(_submenu.menu, _submenu.name, _submenu.descripton, _submenu.price); } } toadd.rows.add("new", "new", "new", "new"); #endregion #endregion }
now need create celldoubleclick handler every grid created. how that?
like other event handler:
toadd.celldoubleclick += toadd_celldoubleclick;
Comments
Post a Comment