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);
}

 




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM