•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 402,523 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,513 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 5881 | Replies: 1
![]() |
•
•
Join Date: Jun 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I have a simple database that displays information in various datagridview controls on the same form. One thing I would like to do is change the colour of a row if the value from a cell returns "poor", or "fair"
I call a private function to go through each row in the datagrid just after it is connected to the bingingSource. I can get it to change the colour, but it formats all the rows with that colour, and I want only the row that returned the value to be changed.
Thanks.
I call a private function to go through each row in the datagrid just after it is connected to the bingingSource. I can get it to change the colour, but it formats all the rows with that colour, and I want only the row that returned the value to be changed.
c# Syntax (Toggle Plain Text)
private void checkForSurveyColour() { foreach (DataGridViewRow row in dataGridView1.Rows) { try { CNumColour = dataGridView1.CurrentRow.Cells["RepVisits"].FormattedValue.ToString(); if (CNumColour != null) { foreach(DataGridViewCell cells in row.Cells) { if (CNumColour == "Fair") { cells.Style.ForeColor = Color.Pink; } else if (CNumColour == "Poor") { cells.Style.ForeColor = Color.Red; } } } } catch(System.Exception ex) { } } }
Thanks.
•
•
Join Date: Oct 2006
Posts: 128
Reputation:
Rep Power: 2
Solved Threads: 1
This might help. You shouldnt have to check if its null because if its not equal to Fair or Poor it wont matter. Also, as long as you have a column within the dataview named RepVisits and you know it will be there ever single time, you dont need the try/catch.
That is much more compact and I believe it should work the same way. The syntax might not be exactly how it should be but if you use visual studio and use the CTL + SPACE shortcuts after puting a period, it helps a lot in finding the proper method/properties you need.
Hope it helped.
private void checkForSurveyColour(DataGridView dv) {
foreach (DataRow dr in dv.Rows) {
if(dr.Cells["RepVisits "].ToString().Equals("Fair") || dr.Cells["RepVisits "].ToString().Equals("Poor") {
dr.Cells["RepVisits"].Style.ForeColor = Color.Red;
}
}That is much more compact and I believe it should work the same way. The syntax might not be exactly how it should be but if you use visual studio and use the CTL + SPACE shortcuts after puting a period, it helps a lot in finding the proper method/properties you need.
Hope it helped.
Last edited by Barefootsanders : Sep 6th, 2007 at 4:42 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP / 2003)
- Login Security ! (PHP)
- delete a row in a sql databse (ASP.NET)
- FlexGrid issue and error "Invalid Row value".... (Visual Basic 4 / 5 / 6)
- javascript works in IE but not working in firefox (JavaScript / DHTML / AJAX)
- How to add rows from dataset to datagridview (C#)
- Newbie Question. how to put url into echo $row (PHP)
Other Threads in the C# Forum
- Previous Thread: how to call C# method in C++
- Next Thread: c# nse File.Delete cannot delete "Temporary Internet Files" files,help me


Linear Mode