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

CellRenderer Deactivating

I have created a cellrenderer derived from GridTextBoxCellRenderer (to prevent the user from typing certain characters). This works fine. But now I want to remove leading zero characters from the cell if a new value has been entered. E.g. if the user enters "003", I want to change that into "3" when the value has been entered. I tried handling OnDeactivating. In OnDeactivating, I get the TextBoxText ("003"), create a new string based on that ("3"), and then set the TextBoxText to that new string. Somehow, the text in the cell reverts to whatever was in there before I started editing. Is there anything else I need to do to enforce my own value?

2 Replies

AD Administrator Syncfusion Team March 5, 2003 05:45 PM UTC

Try overriding OnSaveChanges and do your modifications there before setting it into the style for the cell. Below is the current source.
protected override bool OnSaveChanges()
{
	if (CurrentCell.IsModified)
	{
		GridStyleInfo style = Grid.Model[currentRowIndex, currentColIndex];
		style.FormattedText = this.TextBoxText;
		return true;
	}
	return false;
}


DP Dirk Puis March 6, 2003 06:24 AM UTC

Wew, that works great ... with some modifications. I took out the "if(CurrentCell.IsModified)" because that never seems to be set. I also had to replace currentRowIndex and currentColIndex by CurrentCell.RowIndex and CurrentCell.ColIndex because currentRowIndex and currentColIndex were "inaccessible due to its protection level". So my code looks like this: protected override bool OnSaveChanges() { // Allow subclasses to react to set the // formatted text TrimLeadingZeroes(); GridStyleInfo style = Grid.Model[CurrentCell.RowIndex, CurrentCell.ColIndex]; style.FormattedText = this.TextBoxText; return true; }

Loader.
Live Chat Icon For mobile
Up arrow icon