WinForm 遍历用户控件里CheckBox
2016-05-25 00:13
281 查看
1、常用调用方法
View Code
/// <summary> /// 加载公司组件 /// </summary> private void LoadCompanyComponent() { HRPOWER.BLL.Company _ocompany = new HRPOWER.BLL.Company(); DataTable _dt = _ocompany.GetCompanyInfo(); int LOCATIONX = 218; if (_dt.Rows.Count > 0) { for (int i = 0; i < _dt.Rows.Count; i++) { Parts.UCRightCompany _ucRC = new HRPOWER.WIN.UC.Parts.UCRightCompany(); _ucRC.COMPANYNAME = _dt.Rows[i]["NAME_SHORT"].ToString(); _ucRC.COMPANYID = _dt.Rows[i]["ID"].ToString(); Control c = (Control)_ucRC; c.Location = new Point(LOCATIONX, LOCATIONY); c.Name = "UCRightCompany" + i.ToString(); this.Controls.Add(c); LOCATIONX += 129; } } if (LOCATIONX > this.Width) { this.Width = LOCATIONX + _dt.Rows.Count; } } /// <summary> /// 获取用户对应的权限 /// </summary> /// <param name="cContainer">控件容器</param> private void SearchControls(System.Windows.Forms.Control cContainer) { foreach (System.Windows.Forms.Control c in cContainer.Controls) { if (c is CheckBox) { CheckBox _chb = (CheckBox)c; if (_chb.Checked) { string _sCompID = String.Empty; Control[] ctlList = _chb.Parent.Parent.Controls.Find("chbCompany", true); if (ctlList.Length > 0) { CheckBox chb = (CheckBox)ctlList.GetValue(0); _sCompID = chb.Text; if (MENU.Select("MENUID=" + _chb.Tag.ToString()).Length > 0) { DataRow dr = MENU.Select("MENUID=" + _chb.Tag.ToString())[0]; DataRow ddr = MENU.NewRow(); ddr["USERID"] = dr["USERID"]; ddr["MENUID"] = dr["MENUID"]; ddr["COMPANYID"] = dr["COMPANYID"].ToString().Contains(_sCompID) ? dr["COMPANYID"].ToString() : dr["COMPANYID"].ToString() + _sCompID + ","; MENU.Rows.Remove(dr); MENU.Rows.Add(ddr); } else { DataRow ddr = MENU.NewRow(); ddr["USERID"] = cobID.Text; ddr["MENUID"] = _chb.Tag.ToString(); ddr["COMPANYID"] = _sCompID + ","; MENU.Rows.Add(ddr); } MENU.AcceptChanges(); } } } if (c.HasChildren) SearchControls(c); } }
View Code
相关文章推荐
- leetcode-101
- ORACLE 里面的LIKE 语句的详细作用格式什么呀
- Git 操作标签的一些命令
- 王帅:深入PHP内核
- [leetcode]18. 4Sum
- 单片机 学习笔记(二)——简单小程序
- 15.NSTimer
- 程序员转管理之路
- 推荐算法的文献综述
- 【例题】【动规(分组)】NKOJ 1001 最小乘车费用
- Velt-0.2.6对Python远程调试的支持
- WinForm BaseClass类常用通用方法
- loadrunner在win10破解提示:Cannot save the license information because acceses to the registry is denied的解决办法
- 致在大学中感到迷茫或即将进入大学的你!
- Ant脚本初使用
- c++实验6-矩阵求和
- iOS开发小技巧--学会包装控件(有些view的位置由于代码或系统原因,位置或者尺寸不容易修改或者容易受外界影响)
- SecureCRT 7.3.4破解版(含注册机)
- AutoCloseable,Closeable和Flushable
- 基于LNMP实现动静分离,PHP+Memcached实现会话保持