dev checkedListBoxControl 用法绑定数据,取数据
1、绑定数据,我这里直接绑定Datatable,需要设置DisplayMember(显示的数据),ValueMember(值数据)两个属性,如下
this.checkedListBoxControl1.DisplayMember = "ORA_TWO_CODE"; this.checkedListBoxControl1.ValueMember = "ORAMAP_ID";
完整的绑定代码
private void InitCheckBox() { DataTable dt = OrgManager.GetInstance().GetAll(); this.checkedListBoxControl1.DisplayMember = "ORA_TWO_CODE"; this.checkedListBoxControl1.ValueMember = "ORAMAP_ID"; this.checkedListBoxControl1.DataSource = dt; }
绑定效果如下
2、 取数据
获得勾选的数据
int count = this.checkedListBoxControl1.CheckedIndices.Count;//获得勾选的所有条集合
var chkIndexCollection = this.checkedListBoxControl1.CheckedIndices;//获得所有选中行的集合 for (int i = 0; i < count; i++) { Ora_companyMdl mdl = new Ora_companyMdl(); var sysusers = this.checkedListBoxControl1.DataSource as DataTable; var item = sysusers.Rows[chkIndexCollection[i]];//chkIndexCollection[i]获得选中行在chechedListBOX的index 关键代码
mdl.ORA_TWO_CODE = item["ORA_TWO_CODE"].ToString();
mdl.ORAMAP_ID = this.cmb_company.SelectedValue.ToString();
mdl.ORAMAPS_ID = item["ORAMAP_ID"].ToString();
mdl.ORA_ID = CommonData.GetGuidToLongID(); list.Add(mdl);
}