PC Review


Reply
Thread Tools Rate Thread

DataGridView runtime row formatting

 
 
sklett
Guest
Posts: n/a
 
      6th Sep 2006
I need to format groups of rows separate from other rows depending on a cell
value. I'm sure others have done this as well.

For example, let's say I have 6 rows with a property called 'duration' with
the values:
2
1
5
5
5
7

I want to change the background color of the rows that have the value 5 to a
different color.

I've checked out a couple of the grid's events, but I'm not seeing anything
that sounds correct for this task. Something like "BindingRow".

I suupose that I would need to catch an event for each row's painting or
binding and then get the datasource for the row and then get the property
I'm interested in checking, but I'm not clear how to do this.

Have any of you done this?

I tried this code and ended up with a really funny result:
<code>
int sectionColorIndex = 0;
Color[] sectionColors = new Color[]
{
Color.Gainsboro,
Color.LightSalmon,
Color.LightSeaGreen,
Color.LightSkyBlue,
Color.LightCoral
};
private void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name ==
"DataGridViewComboBoxColumn_OpCode")
{
if (e.Value != null)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor =
sectionColors[sectionColorIndex];
if ((string)e.Value == "DJMPNZSKIP")
{
sectionColorIndex++;
if (sectionColorIndex > 4)
{
sectionColorIndex = 0;
}
Debug.Assert(sectionColorIndex < sectionColors.Length,
"Not enough colors to format grid");
}
}
}
}
</code>
it seems that it's constantly calling format on the cells which results in
an animated DateGrid of my 5 colors. It's funny, but frustrating. I now
know I'm doing this wrong, please help before I vomoit from the colors!!
:0)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
modifying datagridview cells at runtime BillE Microsoft VB .NET 2 27th Aug 2009 04:20 PM
Setting DataGridView's DataSource at runtime? Sin Jeong-hun Microsoft C# .NET 2 20th May 2007 12:00 PM
Trouble ordering the columns of a Datagridview at runtime bappelsin Microsoft C# .NET 0 23rd Aug 2006 01:14 PM
Changing datagridview cells borders at runtime steve Microsoft VB .NET 7 6th Jul 2006 02:57 AM
Changing datagridview cell borders at runtime steve Microsoft VB .NET 10 19th Jun 2006 11:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:49 AM.