We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Exiting edit mode after the user has clicked into a checkbox

I have a bound grid with a column of type checkbox. When the user clicks on the checkbox, I alter some data in the CurrentCellChanged event handler to reflect the new state of the checkbox. At this point the current row is still in edit mode (as shown by the little pencil on the left edge). If the user aborts the edit (e.g. by pressing the ESC key) I have the checkbox reset to the previous state but the data I modified in the event handler stays - of course - changed. I would like to exit edit mode in the event handler, thus automatically confirming the change in the row. Alternatively, I''d like to trap the user operation that undoes the change to the row, so that I could restore the state of my data. So far I have been unable to make either solution work. Can you point me in the right direction? Please note that I''m using v1.6.x Thanks, Raul

4 Replies

AD Administrator Syncfusion Team March 12, 2004 09:15 AM UTC

In CurrentCellChanged, if you are on your checkbox, try this code: this.gridDataBoundGrid1.CurrentCell.EndEdit(); this.gridDataBoundGrid1.Binder.EndEdit();


RR Raul Rosenthal March 12, 2004 10:46 AM UTC

It works, more or less. Now pressing ESC after having clicked on the checkbox doesn''t revert the value of the checkbox to the previous state, but the little pencil doesn''t disappear, which may be a bit confusing to the user. Isn''t there a way to end the edit for the whole row? Thanks, Raul


AD Administrator Syncfusion Team March 12, 2004 01:02 PM UTC

grid.Binder.EndEdit is the proper method to call to get rid of the pencil. The problem is that with a checkbox cell, CurrentCellCahanged is fired before the Binder.BeginEdit call that puts the pencil in place. So, the pencil is appearing after your code is hit in CurrentCellChanged. So, it is being turned off before it is turned on. I looked around for a convenient event that woul doccur after the pencil is shown, an ddid not see one. So, as a not to elegent solution, you could add a timer, and enbled it is CurrentCellChanged, and then turn off the pencil in the tick event.
private void gridDataBoundGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
	//checkboxcell
	if(this.gridDataBoundGrid1.CurrentCell.ColIndex == 1) 
	{
		this.timer1.Interval = 30;
		this.timer1.Enabled = true;
	}
}

private void timer1_Tick(object sender, System.EventArgs e)
{
	this.timer1.Enabled = false;
	this.gridDataBoundGrid1.Binder.EndEdit();
}


RR Raul Rosenthal March 12, 2004 01:34 PM UTC

Boy, this IS ugly. ;-) Nevertheless, I think that I can live with that. Thank you. Regards, Raul

Loader.
Live Chat Icon For mobile
Up arrow icon