I''m trying to assign a cell type to an entire column (excluding headers) in a GridGroupingControl using the following:
myGrid.TableModel.ColStyles["MyCol"].CellType = "MyCellType";
It doesn''t work. Please could you tell me how to this. I know the cell type is registered correctly as I''m able to set it for the entire grid and it works correctly.
myGrid.TableDescriptor.Columns["MyCol"].Appearance.AnyRecordFieldCell.CellType = "Static";
>I''m trying to assign a cell type to an entire column (excluding headers) in a GridGroupingControl using the following:
>myGrid.TableModel.ColStyles["MyCol"].CellType = "MyCellType";
>It doesn''t work. Please could you tell me how to this. I know the cell type is registered correctly as I''m able to set it for the entire grid and it works correctly.
ADAdministrator Syncfusion Team June 16, 2004 12:15 AM UTC
Sean is right. You should modify the Appearance object of the GridColumnDescriptor instead of modifying ColStyles.
ADAdministrator Syncfusion Team June 16, 2004 06:24 AM UTC
Thanks Sean and Stefan, that works perfectly. Is there a way to prevent the custom formatting from being lost when the current cell is set to a cell with a custom renderer?
On my grid, I''ve turned off selection and hidden the current cell:
myGrid.TableOptions.AllowSelection = GridSelectionFlags.None;
myGrid.TableModel.Options.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.HideAlways;
When the user clicks on a cell the value appears to change for no apparent reason.
ADAdministrator Syncfusion Team June 17, 2004 08:31 PM UTC
Does setting this property help?
this.gridGroupingControl1.TableControl.Model.Options.ActivateCurrentCellBehavior = GridCellActivateAction.None;
ADAdministrator Syncfusion Team June 18, 2004 05:49 AM UTC
No, unfortunately the behaviour remains the same.
ADAdministrator Syncfusion Team June 18, 2004 06:08 PM UTC
I think Clay misunderstood your problem. The following explanation should help:
When the cell gets saved the custom renderers OnSaveChanges method gets called. That method then calls CellModel.ApplyFormattedText. CellModel.ApplyFormattedText the parses the formatted text and converts it to the cell value that should be stored in the table.
If you want to avoid that happening you could override the OnSaveChanges method and instead of calling the base class simple set
grid.Model[rowIndex, colIndex].CellValue = ControlText;
Another event you could handle would be QueryCellFormattedText (or TableControlQueryCellFormattedText). That''s when the cell value is converted to the text that should be displayed in the cell.
Let me know if that wasn''t your problem and try explaining it again then.
ADAdministrator Syncfusion Team June 21, 2004 12:53 PM UTC
The grid is read-only, I tried overriding OnSaveChanges and ApplyFormattedText but neither method is ever called.
The cell renderer inherits from GridStaticCellRenderer and overrides OnDraw only:
protected override void OnDraw(System.Drawing.Graphics g, System.Drawing.Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
long amount = (long)style.CellValue;
style.CellValueType = typeof(string);
style.Text = MyCustomFormatting.FormatAsQuantity(amount);
// Highlight negative numbers in red
if (amount < 0)
style.TextColor = Color.Red;
base.OnDraw (g, clientRectangle, rowIndex, colIndex, style);
The problem occurs as soon as you click in the cell. For example if value in the table is 20000 my custom formatting will display 20,000. As soon as the user clicks in the cell the contents change to 20000. This is even more noticable for larger numbers e.g. 1250000 is formatted as 1m250.
I also modified my class that overrides GridStaticCellModel so that in the constructor I subscribe to QueryCellFormattedText events. However, I never receive any of these either.
Please do you have any further suggestions?
ADAdministrator Syncfusion Team June 22, 2004 02:03 PM UTC
Instead of setting style.Text set style.CellValue
- Or -
Override the GetFormattedText(GridStyleInfo style, object value, int textInfo) method of the cell model class. That''s the method that gets called to format the text.
If you have source code, try also setting a breakpoint in your Draw method. Then you can step in to the base class GridStaticCellRenderer.Draw method and see how the cell actually gets drawn. You could also try to draw the cell using the DrawText method yourself instead of calling the base class.
Let me know if that didn''t help either.