Controls on Panel

  • Thread starter Thread starter David
  • Start date Start date
D

David

hello...

I've dinamicaly added textboxex to the panel...
now i want to go thru them (enumerate) how can i do this?
this is not working for me:
foreach (TextBox tb in panel1.Controls)

thanx...
 
Hi David,

foreach(Control c in panel1.Controls)
{
if(c is TextBox)
// do stuff, if necessary, cast to TextBox
}
 
Hi David:
This is another David. I have a recusive way to step though all the controls
on WinForm. All you need to do let the routine know which control you are
looking for though CallBack.

public delegate bool
WinTravelerCallBack(System.Windows.Forms.Control ctrl);

public static void WinTraveler(System.Windows.Forms.Control
ctrls,WinTravelerCallBack winCallBack)
{
foreach(System.Windows.Forms.Control ctrl in ctrls.Controls)
{
// System.Diagnostics.Debug.WriteLine(ctrl.Parent.Name + "
" + ctrl.Name);
if (winCallBack(ctrl))
{
if (ctrl.HasChildren)
WinTraveler(ctrl,winCallBack);
}
else
break;
}
}
 
Back
Top