Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Data Grid View Coding question

Posted on 2011-09-07
2
Medium Priority
?
262 Views
Last Modified: 2012-05-12
Hello Experts

I can do the following:

foreach (TabPage tp in tabc__all.TabPages
   foreach (Control lbl in tp.Controls) lbl.BackColor = Color.Blue;

My question is how do I do the same with datagridviews, so something like the following:


foreach (TabPage tp in tabc__all.TabPages
   foreach (Datagridview dgv in tp.Controls) dgv.BackColor = Color.Blue;

I get an error with this code,  Just a beginning programmer so Detail code please,  Thanks

0
Comment
Question by:crp81
2 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 2000 total points
ID: 36497211
Datagridview foundGrid;

foreach (TabPage tp in tabc__all.TabPages
{
   foreach (Control dgv in tp.Controls) dgv.BackColor = Color.Blue;
   {
          if(dgv is Datagridview)
          {
                 foundGrid = (Datagridview)dgv;
                 foundGrid.BackColor = Color.Blue;
          }
    }
}
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question