public void setData(int id) { ht.Clear(); DataSet ds = bll.selectUserGroups(id); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if (ht.Contains(dr[2].ToString())) { ht[dr[2].ToString()] = Convert.ToBoolean(dr[1].ToString()); } else { ht.Add(dr[2].ToString(), Convert.ToBoolean(dr[1].ToString())); } } foreach (TreeNode node in treeView1.Nodes) { setTreeView(node); } } else { foreach (TreeNode tn in treeView1.Nodes) { tn.Checked = false; if (tn.Nodes.Count > 0) { foreach (TreeNode item in tn.Nodes) { item.Checked = false; } } } } }