The DataGridView control in the Microsoft .NET Framework allows users to edit visual attributes of table elements, such as column, rows and cells. Each cell within the DataGridView control can have its own text font, background and foreground color. The rows, columns and groups of cells share particular style characteristics by default. You need to override the Paint property of the DataGrid class to change the color in one particular cell in DataGridView control.
Click the "Start" button in Windows and select the "Microsoft Visual Studio."
Click "Open" and select the C# program in which you want to change the color in one particular cell in DataGridView control.
Add the following code to the DataGridView control after the "public void DataGrid ()" line in your program:
public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush
foreBrush, bool alignToRight)
object o = this.GetColumnValueAtRow(source, rowNum);
if( o!= null)
char c = ((string)o);
if( c > 'F')
backBrush = new LinearGradientBrush(bounds,
Color.FromArgb(255, 200, 200),
Color.FromArgb(128, 20, 20),
foreBrush = new SolidBrush(Color.White);
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
Click "File" and "Save" to change the color in the "o" cell in the DataGridView control of your program.
- Photo Credit Ablestock.com/AbleStock.com/Getty Images
How to Delete a Row in DataGridView
DataGridView control of Microsoft .NET Framework gives programmers the ability to display user data in a grid. You can edit the data...
How to Change the DataGrid Color in VB6
Users like to see data in an organized and easily accessible format. The Microsoft DataGrid control does just that. It is a...