I've written an app that uses permissions stored in a DB for each control on a given form within the app. How can I go through each Control on a given form and find the coresponding control name (pulled from the DB) and make it Enabled/Disabled?
I know I have to loop through the Controls collection and do that recursively because the given control could have children controls, but I can't seem to get it to work. Here's my code:
this is the FindAllControls method...
I know I have to loop through the Controls collection and do that recursively because the given control could have children controls, but I can't seem to get it to work. Here's my code:
Code:
//Set Permissions...
Permissions oPermissions = new Permissions();
DataSet dsPermissions = oPermissions.GetGroupPermissions(Forms.FormNames.frmMain, Users.Instance.GroupID);
for (int x = 0; x < dsPermissions.Tables[0].Rows.Count; x++)
FindAllControls(dsPermissions.Tables[0].Rows[x], this);
this is the FindAllControls method...
Code:
private void FindAllControls(DataRow dr, Control ctrl)
{
foreach (Control c in ctrl.Controls)
{
if (c.Name == dr["ControlName"].ToString())
c.Enabled = Convert.ToBoolean(dr["Enabled"].ToString());
else if (c.HasChildren)
FindAllControls(dr, c);
}
}