Re: How to format individual cells or rows of a VB.NET DataGrid?
- From: "Mona" <mona@xxxxxxxxxxxxxxx>
- Date: Fri, 1 Jul 2005 12:38:10 +0530
You can do this by inheriting DataGridTextBoxColumn and overriding the Paint
method to conditionally
change the cell format. Here is an example that colors cells based on their
Public Class DataGridColoredTextBoxColumn
Public Sub New()
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal
bounds As Rectangle, ByVal source As CurrencyManager, ByVal rowNum As
Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal
alignToRight As Boolean)
Dim o As Object
o = Me.GetColumnValueAtRow(source, rowNum)
If (Not (o) Is Nothing) Then
Dim c As Char
c = CType(o, String).Substring(0, 1)
If (c = "Test") Then
backBrush = new SolidBrush(Color.Red);
foreBrush= new SolidBrush(Color.White);
Catch ex As Exception
' empty catch
MyBase.Paint(g, bounds, source, rowNum, backBrush,
Hope this helps.
"Richard" <Richard@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>I know that you can format a grid and its columns using DataGridTableStyle
> and DataGridTextBoxColumn in VB.NET. But can you change the format of the
> individual rows, or even cells, to something other than the default?
> For instance, I have a datagrid displaying a list of products in stock. I
> want to highlight the products in red if the product is out of stock. How
> should I implement this?
> Please let me know if you have the answer. Thanks.
- Prev by Date: Re: Sample Database projects
- Next by Date: Help: Compilation trouble ??
- Previous by thread: Re: Debug and break point problem - There is no source code available
- Next by thread: Re: How to format individual cells or rows of a VB.NET DataGrid?