Finding all controls of specified type on a form
From: Joe S. (dontmail_at_nowhere.com)
Date: 08/08/04
- Next message: Andrew Smith \(Infragistics\): "Re: Finding all controls of specified type on a form"
- Previous message: Sergei Shelukhin: "saveFileDialog - bug & question"
- Next in thread: Andrew Smith \(Infragistics\): "Re: Finding all controls of specified type on a form"
- Reply: Andrew Smith \(Infragistics\): "Re: Finding all controls of specified type on a form"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 8 Aug 2004 23:36:04 +0200
I need to find all instances of a specific type of control on a Windows
Form -- for example all DataGrids. The code I came up with is this:
foreach(Control ctrl in this.Controls)
{
if(ctrl.GetType() == Type.GetType("System.Windows.Forms.DataGrid"))
Console.WriteLine(((DataGrid)ctrl).Name);
}
This code has two problems. Something's wrong with the type checking,
because it doesn't find any DataGrids on a form.
Even if it did work, the second problem is that this would find only
DataGrids put directly on the form (in the Form.Controls collection), but a
Grid can also be in the ControlCollection of a GroupBox or some other
container. How to loop through all controls in a form regardless of their
parent control?
Best regards,
Joe
- Next message: Andrew Smith \(Infragistics\): "Re: Finding all controls of specified type on a form"
- Previous message: Sergei Shelukhin: "saveFileDialog - bug & question"
- Next in thread: Andrew Smith \(Infragistics\): "Re: Finding all controls of specified type on a form"
- Reply: Andrew Smith \(Infragistics\): "Re: Finding all controls of specified type on a form"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|