Iterate all controls in BindingNavigator
I have some windows forms that each has some controls including buttons,ComboBox,... and also in each form i have a Bindingnavigator control that i added some new Toolstrip buttons to it, how can i write a general method that get 3 parameters and iterate all controls on a form(including that toolstrip buttons) and enable/disable Enabled status of an special control? my method signature is like this:
Public SetStatusOf(Form frm,string controlName,bool status)
Answers
From the question, and from what I understood, you need this:
foreach (Control c in frm.Controls) { if (c.Name.Equals(controlName)) c.Enabled = status; }
but you can also directly use
frm.Controls[controlName].Enabled = status;