dev checkedListBoxControl 介绍

1、 给checkedListBoxControl绑定数据源:

        checkedListBoxControl.DataSource = listRole;
        checkedListBoxControl.DisplayMember = "roleName";
        checkedListBoxControl.ValueMember = "ID"; 

2、打钩checkedListBoxControl控件里的某一项:

       checkedListBoxControlRole.SetItemChecked(i, true); //i是控件的索引值

3、获取checkedListBoxControl控件里某一项的ValueMember值

       checkedListBoxControlRole.GetItemValue(i).ToString();//i是控件的索引值

4、实现checkedListBoxControl控件点击一次就可以选中复选框,设置CheckOnClick属性为true,即可。

5、取数据

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

如何设置checkedListBoxControl1的单选:这边我增加了一个checkEdit1按钮,checkEdit1为true时才可多选。

	  private void checkedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
			{
				if (checkEdit1.Checked == false)
				{
					if (e.State == CheckState.Checked)
					{
						//循环遍历项目
						for (int i = 0; i < checkedListBoxControl1.ItemCount; i++)
						{
							//把非当前的项目全部设置为没选中
							if (i != e.Index)
								checkedListBoxControl1.SetItemCheckState(i, CheckState.Unchecked);
						}
					}
				}
			}

	获取的值:
				foreach (Record ss in checkedListBoxControl1.CheckedItems)
				{
					textEdit2.Text = ss.Name;
				}
posted @ 2022-11-09 17:04  mkmkbj  阅读(360)  评论(0编辑  收藏  举报