views:

65

answers:

3

Lets say I have multiple DataGrids throughout my winform app and I want to set the BackColor on ALL of them to Purple in Visual Studio.

What is the fastest way of setting a Property for multiple items NOT located on the same Form?

Thanks!

+2  A: 

There is an Application.OpenForms property - you can loop over that list, then loop over the Controls property of each control recursively, modding those that match your type.

Is that the kind of thing you're looking for?

Mike
Oops, I meant in Visual Studio, not at runtime. Thank you though as I did not know that either!
Refracted Paladin
+2  A: 

Since you're asking about changing this at design time and not runtime, I would do a search on your whole solution for "new DataGrid" and change them in the designer.cs (or designer.vb) files. Other than that, I can't think of a quicker way other than maybe writing some sort of macro.

Scott Anderson
Oh, I always thought changes in the Designer got overwritten by the UI. I didn't realize that it worked the other way as well.
Refracted Paladin
+1  A: 

Hi,

Rather than search for "new DataGrid", why not search for ".BackColor =" which is the line you'll be changing (keeping in mind that other controls have a .BackColor property so don't just do a blind update).

Hope this helps,

Bill

Bill Mueller