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
close icon

cell format & EnterKeyBehavior

I am simulating a percent cell using a method described in another forum thread. This is fine all the time that hitting Enter causes movement to another cell. With EnterKeyBehavior=Right, hitting Enter in the right most column results in no movement(as expected)and so the % value is not displayed correctly until manually leaving the cell. How can I force the cell to display correctly in this situation? I have attached a small example which has a grid with 2 columns. Try inserting values & hitting Enter to see the problem. Regards, Mick TestPerc_8040.zip

2 Replies

AD Administrator Syncfusion Team April 12, 2005 04:47 PM UTC

Selectively calling CurrentCell.EndEdit when you are in the last column worked around the problem in your sample. The code is below. Another option is to make the enter wrap to the next row. You can do this by setting a property. this.grid.Model.Options.WrapCellBehavior = GridWrapCellBehavior.WrapRow; But in this case, the sample problem will exist on the bottom most-right most cell. So, you would have to call EndEdit on the last cell in the grid to force the cell to lose focus in that case.
private bool inEvent = false;
private void grid_CurrentCellValidating(object sender, CancelEventArgs e)
{
	GridControlBase grid = sender as GridControlBase;
	GridCurrentCell cc = grid.CurrentCell;

	if(!inEvent && grid.Model[cc.RowIndex, cc.ColIndex].Format == "P2")
	{
		string s = cc.Renderer.ControlText;
		if(s.IndexOf("%") > -1)
			s = s.Replace("%","");
		double d;
		if(double.TryParse(s, System.Globalization.NumberStyles.Any, null, out d))
		{
			d/=100;
			cc.Renderer.Control.Text = d.ToString();
		}
		
		if(cc.ColIndex == grid.Model.ColCount)
		{
			inEvent = true;
			cc.EndEdit();
			inEvent = false;
		}
	}
}


MS Mick Speake April 12, 2005 04:53 PM UTC

Many thanks, Clay. I tried cc.EndEdit() but failed as I didn''t know about "inEvent"! Regards, Mick

Loader.
Live Chat Icon For mobile
Up arrow icon