473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DatagridView Formatting Issue

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 Datagridview datasource is a
datatable. Currently my issue is that all records are painted red on the
Cell_Formatting event. But not all records meet the filter condition. Any
ideas why? Here is code snippet

private void dgvPolicies_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
DataView view = (DataView)dgvPolicies.DataSource;

foreach (DataRowView rowView in view)
{
//if (rowView.Row.ItemArray[3].ToString().ToLower() == "test")
if (rowView.Row.ItemArray[24].ToString() == bool.TrueString)
{
e.CellStyle.ForeColor = Color.Red;
}
}
}
Jun 4 '07 #1
2 2059
Toco,

In your formatting event you should not loop throgh all rows inside your
view - only use the one for the current row:
DataView view = (DataView)dgvPolicies.DataSource
if (view[e.RowIndex].Row.ItemArray[24].ToString() == bool.TrueString)
{
e.CellStyle.ForeColor = Color.Red;
}
otherwise all your cells will be red as long as there is at least one recods
that meets your condition.

"Toco" wrote:
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 Datagridview datasource is a
datatable. Currently my issue is that all records are painted red on the
Cell_Formatting event. But not all records meet the filter condition. Any
ideas why? Here is code snippet

private void dgvPolicies_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
DataView view = (DataView)dgvPolicies.DataSource;

foreach (DataRowView rowView in view)
{
//if (rowView.Row.ItemArray[3].ToString().ToLower() == "test")
if (rowView.Row.ItemArray[24].ToString() == bool.TrueString)
{
e.CellStyle.ForeColor = Color.Red;
}
}
}
Jun 5 '07 #2
Thank you Sergey, that is what I needed.

"Sergey Poberezovskiy" wrote:
Toco,

In your formatting event you should not loop throgh all rows inside your
view - only use the one for the current row:
DataView view = (DataView)dgvPolicies.DataSource
if (view[e.RowIndex].Row.ItemArray[24].ToString() == bool.TrueString)
{
e.CellStyle.ForeColor = Color.Red;
}
otherwise all your cells will be red as long as there is at least one recods
that meets your condition.

"Toco" wrote:
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 Datagridview datasource is a
datatable. Currently my issue is that all records are painted red on the
Cell_Formatting event. But not all records meet the filter condition. Any
ideas why? Here is code snippet

private void dgvPolicies_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
DataView view = (DataView)dgvPolicies.DataSource;

foreach (DataRowView rowView in view)
{
//if (rowView.Row.ItemArray[3].ToString().ToLower() == "test")
if (rowView.Row.ItemArray[24].ToString() == bool.TrueString)
{
e.CellStyle.ForeColor = Color.Red;
}
}
}
Jun 5 '07 #3

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...
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...
8
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
If I populate a DataGridView with a query supplied at runtime, boolean fields render as a CheckBox instead of just a text rendering of '0' or '1'. That is nice sometimes, but I would like the...
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...
6
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab...
3
by: Stewart Berman | last post by:
I have an application that populates a DataGridView control with an XML file: private void Form1_Load(object sender, EventArgs e) { dataGridView1.DataSource = gridDataSet;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.