$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView for Windows Forms
Create data gird view in C# with modern user interface for your Windows Forms applications
Home > WinForms UI Controls > User Manual > Painting Rows in C#

Draw and Paint Grid Rows for C# DataGridView

The DataGridView C#.NET Component allows users to draw and paint rows to their GridView when the current rows can’t meet their requirements to Windows Forms applications. When enabling this rows painting functionality, the DataGridView control is able to create custom painting rows to C# GridView in .NET Windows Forms applications. This is accomplished through using the RowPaint event in C#.NET template projects.

How to Paint Rows to GridView in C#

Enable the Rows Painting in C#

When we want to paint rows to GridView in C# Windows Forms projects, we need to fire the RowPaint event by changing the value of the property, EnableCustomDrawing, to true for the Kettic DataGridView control. It is able to apply the scenario that uses the RowPaint event while we want to apply custom painting to extend the row appearance to GridView in C# Windows Forms applications. The following is a simple C# code snippet that shows how to enable the EnableCustomDrawing property to the event for rows painting.

ketticGridView.EnableCustomDrawing = true;

Customize Grid Rows Appearance in C#

We are going through an example to customize the row appearance based on the UnitsInStock cell value to DataGridView for C# Windows Forms application. When the cell value is greater than 10, it will not apply custom painting to rows and the gird rows will be drawn by default setting. When the cell value is less than 10, the Kettic GridView control will draw an additional border inside the row to display that the product unites in stock. We need to access the grid row through the parameters of the event handler instead of accessing the grid rows directly. The following are the C# code that shows how to customize the row appearance to GridView control.

private void ketticGridView1_RowPaint(object sender, GridViewRowPaintEventArgs e)
{
GridDataRowElement dataRow = e.Row as GridDataRowElement;

if (dataRow != null)
{
double value = Convert.ToDouble(dataRow.RowInfo.Cells["UnitsInStock"].Value);

if (value < 10)
{
return;
}

Pen pen = value < 0 ? Pens.Purple : Pens.RoyalBlue;
Size rowSize = dataRow.Size;
rowSize.Height -= 6;
rowSize.Width -= 5;
e.Graphics.DrawRectangle(pen, new Rectangle(new Point(2, 2), rowSize));
}
}
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