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

Custom Cell Model - Change CellValue Issue!

Hi guys! I'm trying to create a custom cell model which alters the displayed value (cell value) of bound data for specific cells. My solution seems to work except when 'on' the current cell. Are you only supposed to change cell values for this purpose in the grid event QueryCellInfo or is my way valid and just not working properly? The reason why I want this is to define special custom grid column types which can show 'Hello Wo...' for truncated text in addition to other more application specific needs. I have attached a sample app which shows the problem. Thanks in advance, Marcus.

2 Replies

AD Administrator Syncfusion Team October 21, 2003 08:01 AM UTC

You could do this in a PrepareViewStyleInfo event handler without deriving a cell control. But deriving a cell control will probably be more efficient as PrepareViewStyleInfo is hit a lot. In your OnDraw override, do not call the baseclass to do the drawing. In the base class, the value stored in the original style is drawn and you do not want this. Instead, call the static GridStaticCellRenderer.DrawText method to draw the text. Doing so, allows you to specify the exact text to be drawn.
protected override void OnDraw(System.Drawing.Graphics g, System.Drawing.Rectangle clientRectangle, 
			int rowIndex, int colIndex, GridStyleInfo style)
{
	int i = (int)style.CellValue * 10;
	//style.CellValueType = typeof(string);
	//style.CellValue = "Val = " + i.ToString();
	string text = "Val = " + i.ToString();
	//base.OnDraw(g, clientRectangle, rowIndex, colIndex, style);
	GridStaticCellRenderer.DrawText(g, text, style.GdipFont, clientRectangle, style, style.TextColor);
}


AD Administrator Syncfusion Team October 21, 2003 08:07 AM UTC

Try overriding the GridCellModelBase.GetFormattedText method or handle the GridModel.QueryFormattedText event. Then there is no need to change the .CellValue in OnDraw. If you then still want to change the contents of the current cell try handling the CurrentCellInitializeControlText event. Stefan

Loader.
Up arrow icon