Monday, 15 April 2013

c# winforms: searching for datagridview event that will fire after changing cell value AND cell focus -



c# winforms: searching for datagridview event that will fire after changing cell value AND cell focus -

i need execute logic if , if value of particular cell changes , focus has shifted cell. logic needs executed if both value has changed , focus has changed...i.e. user has finished editing cell , moving on. should not go off changing cell focus...only if value changed. i've been searching , experimenting events , have been unsuccessful far.

please note...this unbound grid view populated programmatically. have loved have used conventional bound grid view have utilize because of how our existing code written.

this have tried...

datagridview.cellvalidated "occurs after cell has finished validating." fires when alter cell value...and afterwards every time alter cell focus regardless of if alter cell value after first time. not fit needs because keeps getting called whenever move focus...even if there not alter in value.

datagridview.cellvalidating "occurs when cell loses input focus, enabling content validation." not seem need either.

datagridview.cellvaluechanged "occurs when value of cell changes." fires every time alter value...before shifting focus. not useful either purposes.

i don't know if using right event , or not setting property somewhere or not calling method alter state of grid view. help appreciated.

thanks, john

use cellvalidating event check if value has changed or not set on globale boolean , save current cell row index , column, , on selectionchanged event check if value alter : if hasn't alter utilize datagridcurrentcell set focus on save index row , column saved

datagridview_cellvalidating(object sender, datagridviewcellvalidatingeventargs e) { if(e.formattedvalue == (theoldvalue)) { changed = false; currentindexrow= e.rowindex; currentindexcolumn= e.columnindex; e.cancel = true; } } datagridview_selectionchanged(object sender, eventargs e) { if(!changed) datagridview.currentcell = datagridview.rows[currentindexrow].cells[currentindexcolumn]; }

c# winforms events datagridview

No comments:

Post a Comment