Datagrid row format

  • Thread starter Thread starter grmAbay
  • Start date Start date
G

grmAbay

Is it possible to format a row differently based on th einformation in the
row.

For example:
I have a list of orders.
I want all orders of today in blue text. All orders of this week in green,
and the rest black.
 
Hi,

derive your own columnstyles, and override the paint method to implement row based formatting:

protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight )
{
// Paint the column values
// get the current cell value from the data source
object value = this.GetColumnValueAtRow( source, rowNum );
// and format it
string text;
if ( value == null || value == DBNull.Value ) text = this.NullText;
else text = value.ToString();
// clear the cell backgound
Brush bgBrush = new SolidBrush( this.DataGridTableStyle.BackColor );
Brush fgBrush= new SolidBrush( this.DataGridTableStyle.ForeColor );
g.FillRectangle( bgBrush, bounds );
// and paint the value in the reduced bounds
g.DrawString( text, this.DataGridTableStyle.DataGrid.Font, fgBrush, bounds );
}

Take it as a starter....
HTH,
ulli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top