473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataGridView runtime row formatting

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)
Sep 6 '06 #1
0 3179

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bob | last post by:
Now this ought to be a simple matter. But nothing's simple in the Net world, I'm finding. In vb6 you could use "!" to force text to upper case in the format function. I've searched the vb.net...
2
by: ScottL | last post by:
Hi - I have an issue with the DataGridView. I am formatting the DGV in code and not using the designer. I drop a DGV on my form, code the formatting including some columns.visible = false. After...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
8
by: Brian Pelton | last post by:
This is on .Net 2.0 in a WinForms application. I have a DataGridView that is bound to a BindingSource. The DataGridView has 3 columns. The first two are "normal" text columns and the last is a...
6
by: Terry Olsen | last post by:
I have two DataGridView's loaded from their respective datasources. I want to highlight rows in one DataGridView that are also in the other DataGridView. But the following code does not work....
2
by: =?Utf-8?B?VG9jbw==?= | last post by:
Hello. My goal is to pain the entire row fore color as Red. If the value of column 24 is true (boolean), I wish to paint the row as Red. Otherwise, leave row as default (no formatting). The...
1
by: Jeff | last post by:
Hey ..NET 2.0 I've created a User Control which contain a DataGridView. This User Control is displayed on a TabPage. This TabPage is added to the TabControl during runtime. The problem is...
4
by: NvrBst | last post by:
I have a log viewer. I sort the DataGridView by the Time Column and then run a function to set all cell backcolors depending if the cell above is different. This works correctly, however, when...
1
by: Ben456 | last post by:
Hello, I'm trying to figure out how to keep my cell formatting the same even after I've clicked a column sort header. Basically I've programmatically changed forecolors and backcolors of...
2
by: TG | last post by:
Hi! I am trying to export only the visible columns from a datagridview in my windows form in VB 2008. Should't it be no comma after the first row where the headers are? Also should...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.