c# - How to add checkbox control at the beginning of every row in datagrid control? -
i developing mobile application in c#. want add checkbox control dynamically @ beginning of every row in datagrid control & based on particular checkbox selection want fire event. want add checkbox column & based on selection of particular checkbox, want fire event on checkbox selected row. using following code.
private void showregistrationkeydetails_load(object sender, eventargs e) { gridheight = 40; sqlitedatareader sqlitedrkeyobj = null; datatable dt = new datatable(); datamanager datamgrobj = new datamanager(); //int keyid = cust_id; //string client_key1 = client_key; int keyid = selected_customer_id; //string client_key = selected_client_key; sqlitedrkeyobj = datamgrobj.getregistrationkey(keyid); dt.load(sqlitedrkeyobj); //dt.columns.add(new datacolumn("select", typeof(boolean))); regkeyinfodatagrid.datasource = dt; sizecolumns(regkeyinfodatagrid); regkeyinfodatagrid.height = gridheight; } protected void sizecolumns(datagrid grid) { //grid.controls.add(new checkbox()); graphics g = creategraphics(); datatable datatable = (datatable)grid.datasource; //datacolumn dtccheck = new datacolumn("ismandatory");//create data ////column object name //dtccheck.datatype = system.type.gettype("system.boolean");//set ////data type //dtccheck.defaultvalue = false;//set default value //datatable.columns.add(dtccheck);//add above column //data table //set data grid source data table createed above //grid.datasource = datatable1; // set style property when first time grid loads, next time onwards // maintain property datagridtablestyle datagridtablestyle = new datagridtablestyle(); datagridtablestyle.mappingname = datatable.tablename; int rowcount = datatable.rows.count; //foreach( foreach (datacolumn datacolumn in datatable.columns) { int maxsize = 0; sizef size = g.measurestring( datacolumn.columnname, grid.font ); if (size.width > maxsize) maxsize = (int)size.width; //grid.controls.add(new checkbox()); foreach (datarow row in datatable.rows) { size = g.measurestring( row[datacolumn.columnname].tostring(), grid.font ); if (size.width > maxsize) maxsize = (int)size.width; // autoresize datagrid control string act_date = datacolumn.columnname; if (act_date == "activation_date") { gridheight = gridheight + 17; //checkbox chk = new checkbox(); //chk.location = new point(20, 30); //this.controls.add(chk); //datatable.rows.add(new checkbox()); } } datagridcolumnstyle datagridcolumnstyle = new datagridtextboxcolumn(); datagridcolumnstyle.mappingname = datacolumn.columnname; datagridcolumnstyle.headertext = datacolumn.columnname; datagridcolumnstyle.width = maxsize + 5; datagridtablestyle.gridcolumnstyles.add(datagridcolumnstyle); } grid.tablestyles.add(datagridtablestyle); g.dispose(); } private void backmenuitem_click(object sender, eventargs e) { querydetails querydetailsobj = new querydetails(); querydetailsobj.show(); }
can please provide me code or link through can resolve above issue?
there example of adding check box datagrid:
http://www.codeproject.com/articles/2652/adding-a-checkbox-column-to-your-datagrid
Comments
Post a Comment