c# - How to add a checkbox control to a datatable? -


how can add checkbox datatable , bind datagrid?

datatable columnlist = new datatable(); columnlist.columns.add("column fields");  int j = 1, = 0; checkbox colcheckbox = new checkbox(); foreach (columns col in columnnames) {     colcheckbox.name = col.columnname;            columnlist.rows.add(colcheckbox); // getting displayed system.windows.forms.checkbox,checkstate=0 } 

please help.

you'll have have boolean field (column) in datatable. when bind datatable datagridview, checkbox column created boolean field.

sample code:

var dt = new datatable(); dt.columns.add(new datacolumn("selected", typeof(bool))); //this show checkboxes dt.columns.add(new datacolumn("text", typeof(string)));   //this show text  var dgv = new datagridview(); dgv.datasource = dt; 

this bind dt datatable dgv datagridview. datagridview automatically display datagridviewcheckboxcolumn first datacolumn (selected) , datagridviewtextboxcolumn second datacolumn (text).


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -