Thursday 13 October 2011

Settings the controls in Windows Form

Questions Received:
        How to set/unset the controls in the Windows Form

Solution:
        To find the required using the accessible name of the controls, use the 'find' method in
Form.Controls.find().
        public static void set(Control form,string ctrlName,string DBName)
        {
            foreach (Control ctrl in form.Controls.Find(ctrlName, true))
            {
                if (ctrl is CheckBox)
                {
                    CheckBox chk = (CheckBox)ctrl;
                    if (chk != null)
                    {
                        chk.Checked = true;
                    }
                }
                if (ctrl is TextBox)
                {
                    TextBox tb = (TextBox)ctrl;
                    if (tb != null)
                    {
                        tb.Text = DBName;
                    }
                }
            }
        }

[Note:] Assume, Form-->this, ctrlName-->AccessibleCtrlName, DBName-->TextFieldEntry
           You can use this function to manage different controls in the Form

No comments:

Post a Comment