$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView for C#.NET WinForms
Create custom data grid cells to GirdView in C# for your .NET Windows Forms applications
Home > WinForms UI Controls > User Manual > Drawing Cells in C#

Painting and Drawing in Cells to C# GridView

The Kettic DataGridView control provides the support of painting and drawing in grid data cells to for DataGridView component in Windows Forms application. The data grid cells painting and drawing functionality is able to extend the grid data cell appearance and offer additional information relevant to the grid cell data to users of the control. The Kettic DataGridView C#.NET control provides the CellDraw event to achieve this and the CellDraw event functionality can be enabled by changing the value of EnableCustomPainting property to true.

How to Draw in Grid Cell in C#.NET

To draw in cells for extend the data grid cell appearance and offer additional information of grid data to users, we need to enable the CellDraw event to C# GridView component first. While handling this event, we need to access the grid data cell via the parameters of the event handler instead of the grid data cell directly.

C# code for Painting in Grid Data Cell

We are going through an example as below to learn the process of using the CellDraw event to style the grid cells appearance in the ProductPrice column of C# DataGridView component. In this example, we will create a custom painted blue asterisk to values less than 30, a yellow asterisk to values larger than 30, and no asterisk when the grid cell's value is zero. C# code for painting and drawing in grid data cells to DataGridView component.

void ketticGridView_CellDraw(object sender, Kettic.WinForms.UI.GridViewCellDrawEventArgs e)
{
DataGridCellElement dataCell = e.Cell as DataGridCellElement;

if (dataCell != null && dataCell.ColumnInfo.Name == "ProductPrice")
{
double value = Convert.ToDouble(dataCell.Value);
if (value == 0)
{
return;
}

Brush brush = value < 30 ? Brushes.Blue : Brushes.Yellow;
Size cellSize = e.Cell.Size;

using (Font font = new Font("Arial UI", 25))
{
e.Graphics.DrawString("*", font, brush, Point.Empty);
}
}
}
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls