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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to display custom error icon at left side of the cell in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl

Display custom error icon

To draw an error icon at the left side of the cell text rectangle, use the CustomCellRenderer and CustomCellModel for GridTextBoxCellRenderer and GridTextBoxCellModel respectively. Then, override the OnDraw method in CustomCellRenderer.

Creating Cell Model


public class CustomCellModel : GridTextBoxCellModel
    public CustomCellModel(GridModel grid)
        : base(grid)
    public override GridCellRendererBase CreateRenderer(GridControlBase control)
        return new CustomCellRenderer(control, this);



Public Class CustomCellModel
    Inherits GridTextBoxCellModel
    Public Sub New(ByVal grid As GridModel)
    End Sub
    Public Overrides Function CreateRenderer(ByVal control As GridControlBase) As GridCellRendererBase
        Return New CustomCellRenderer(control, Me)
    End Function
End Class


Creating Cell Renderer


public class CustomCellRenderer : GridTextBoxCellRenderer
    public CustomCellRenderer(GridControlBase grid, GridCellModelBase cellModel)
        : base(grid, cellModel)
    protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
        if (this.Grid.CurrentCell.HasCurrentCellAt(rowIndex, colIndex) && this.Grid.CurrentCell.IsEditing
            && !this.Grid.CurrentCell.IsValid)
            Rectangle rect = clientRectangle;
            Bitmap bitmap = SystemIcons.Error.ToBitmap();
            rect = GridUtil.CenterInRect(rect, new Size(20, 20));
            g.DrawImage(bitmap, new Rectangle(clientRectangle.X, rect.Y, bitmap.Width -10, rect.Height));
            base.OnDraw(g, new Rectangle(clientRectangle.X + bitmap.Width, clientRectangle.Y, clientRectangle.Width - bitmap.Width, clientRectangle.Height), rowIndex, colIndex, style);
            base.OnDraw(g, clientRectangle, rowIndex, colIndex, style);



Public Class CustomCellRenderer
    Inherits GridTextBoxCellRenderer
    Public Sub New(ByVal grid As GridControlBase, ByVal cellModel As GridCellModelBase)
        MyBase.New(grid, cellModel)
    End Sub
    Protected Overrides Sub OnDraw(ByVal g As Graphics, ByVal clientRectangle As Rectangle, ByVal rowIndex As Integer, ByVal colIndex As Integer, ByVal style As GridStyleInfo)
        If Me.Grid.CurrentCell.HasCurrentCellAt(rowIndex, colIndex) AndAlso Me.Grid.CurrentCell.IsEditing AndAlso (Not Me.Grid.CurrentCell.IsValid) Then
            Dim rect As Rectangle = clientRectangle
            Dim bitmap As Bitmap = SystemIcons.Error.ToBitmap()
            rect = GridUtil.CenterInRect(rect, New Size(20, 20))
            g.DrawImage(bitmap, New Rectangle(clientRectangle.X, rect.Y, bitmap.Width - 10, rect.Height))
            MyBase.OnDraw(g, New Rectangle(clientRectangle.X + bitmap.Width, clientRectangle.Y, clientRectangle.Width - bitmap.Width, clientRectangle.Height), rowIndex, colIndex, style)
            MyBase.OnDraw(g, clientRectangle, rowIndex, colIndex, style)
        End If
    End Sub
End Class


Adding CellModel and Assigning CellType


this.gridGroupingControl1.TableControl.CurrentCell.ShowErrorIcon = false;
this.gridGroupingControl1.TableModel.CellModels.Add("CustomCell", new CustomCellModel(this.gridGroupingControl1.TableModel));
this.gridGroupingControl1.TableDescriptor.Appearance.AnyRecordFieldCell.CellType = "CustomCell";



Me.gridGroupingControl1.TableControl.CurrentCell.ShowErrorIcon = False
Me.gridGroupingControl1.TableModel.CellModels.Add("CustomCell", New CustomCellModel(Me.gridGroupingControl1.TableModel))
Me.gridGroupingControl1.TableDescriptor.Appearance.AnyRecordFieldCell.CellType = "CustomCell"


Display the customize error icon


C#: CustomizeErrorIcon_CS

VB: CustomizeErrorIcon_VB


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile