Solved

Data Grid View Coding question

Posted on 2011-09-07
2
254 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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