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,
ADAdministrator Syncfusion Team October 21, 2003 04:01 AM
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);
ADAdministrator Syncfusion Team October 21, 2003 04:07 AM
Try overriding the GridCellModelBase.GetFormattedText
method or handle the
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.