c# - DataGridViewCheckBoxColumn get state -


i've got datagridview dgview populate several different forms, e.g. datagridviewcheckboxcolumn. handle events, added

private void initializecomponent() {     ...     this.cellclick += new system.windows.forms.datagridviewcelleventhandler(this.dgview_cellclick);     ... } 

the implementation looks like:

private void dgview_cellclick(object sender, datagridviewcelleventargs e) {     if (columns[e.columnindex].name == "name of checkboxcolumn")   // valid , returns true     {         console.writeline("handle single click!");         // how state of checkboxcolumn ??     }  } 

this stuck. tried different approaches no success @ all:

datagridviewcheckboxcolumn cbcol = rows[e.rowindex].cells[e.columnindex] datagridviewcheckboxcolumn; // not work datagridviewcheckboxcolumn cbcol = (datagridviewcheckboxcolumn)sender; // nor if (bool.tryparse(rows[e.rowindex].cells[e.columnindex].editedformattedvalue.tostring(), out isbool)) // nor { ... } 

could point out how retrieve state of checkboxcolumn please? besides, other events exist address checkboxcolumn directly? (such "valuechanged" or something)

update: approach

datagridviewcell dgvcell = rows[e.rowindex].cells[e.columnindex]; console.writeline(dgvcell.value); 

at least returns true / false @ point of time before value gets changed (or not) clicking cell. in there should solution address checkboxcolumn directly.

solution: answer obvious see. problem facing event "cellclick" triggered when clicking on cell clicking on checkbox. proper handling therefore use "cellvaluechanged" event instead:

 private void initializecomponent()  {       ...       this.cellvaluechanged += new system.windows.forms.datagridviewcelleventhandler(this.dgview_cellvaluechanged);       ...  } 

to determine value of checkbox use same way stated above:

 if (e.columnindex != -1 && columns[e.columnindex].name == "name of checkbox")  {       bool cbval = rows[e.rowindex].cells[e.columnindex].value;  } 

one way manipulate ui components use of data bindings. see example:

 <datagrid.columns>     <datagridcheckboxcolumn header="online order?" isthreestate="true" binding="{binding onlineorderflag}" /> </datagrid.columns> 

this links explains datagrid usage in detail. anyways, have tried doing quickwatch sender see type of it?


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -