CheckComboboxEdithtml
//清空項
checkedComboBoxEdit1.Properties.Items.Clear();spring
//自定義數組
string[] strs=new string[]{"新建","審批中","已完成","已撤銷"};
//添加項
checkedComboBoxEdit1.Properties.Items.AddRange(strs);數組
//設置選中狀態
if(checkedComboBoxEdit1.Properties.Items.Count>0){
//設置選中狀態
checkedComboBoxEdit1.Properties.Items[strs[0]].CheckState = CheckState.Checked;
//設置選項是否可用
checkedComboBoxEdit1.Properties.Items[strs[0]].Enabled = false;
}
//取值
checkedComboBoxEdit1.EditValue.ToString();
//獲取各項值 放在List集合中
List<object> List = checkedComboBoxEdit1.Properties.Items.GetCheckedValues();spa
//注意 當取得值是多項時,各項之間的間隔是 英文狀態下 逗號+空格
//轉換方法
string result = checkedComboBoxEdit1.EditValue.ToString().Replace(", ", ",");.net
//是否顯示 肯定、取消按鈕
checkedComboBoxEdit1.Properties.ShowButtons = false;
//是否顯示 取消按鈕
checkedComboBoxEdit1.Properties.ShowPopupCloseButton = false;code
//下拉顯示項的個數 (設置爲下拉個數加1正好能夠顯示所有,由於有一行是全選項)
checkedComboBoxEdit1.Properties.DropDownRows = checkedComboBoxEdit1.Properties.Items.Count + 1;htm
CheckedListBoxControlblog
//自定義一個表
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Sex");
for (int i = 0; i < 30; i++) {
DataRow dr = dt.NewRow();
dr["ID"] = i + 1;
dr["Name"]=Convert.ToString((char)(65+i))+Convert.ToString((char)(65+i));
dr["Sex"] = i % 2==0?"男":"女";
dt.Rows.Add(dr);
}
//清空項
checkedListBoxControl1.Items.Clear();ip
//綁定
checkedListBoxControl1.DataSource = dt;
checkedListBoxControl1.ValueMember = "ID";
checkedListBoxControl1.DisplayMember = "Name";string
//全選
//checkedListBoxControl1.CheckAll();
//項的個數
int itemCount = checkedListBoxControl1.ItemCount;
//添加項(若是設置綁定,添加項無效)
checkedListBoxControl1.Items.Add("kk");
//設置選中狀態、顯示值、實際值、是否可用(若是設置綁定,這些將會無效)
checkedListBoxControl1.Items[0].CheckState = CheckState.Checked;
checkedListBoxControl1.Items[0].Description = "顯示值";
checkedListBoxControl1.Items[0].Value = "實際值";
checkedListBoxControl1.Items[0].Enabled = false;
//效果和上面同樣
checkedListBoxControl1.SetItemChecked(0, true);
checkedListBoxControl1.SetItemCheckState(0, CheckState.Checked);
checkedListBoxControl1.SetItemValue("實際值",0);
//是否被勾選
bool isChecked= checkedListBoxControl1.GetItemChecked(0);
//獲取某項狀態
string checkState = checkedListBoxControl1.GetItemCheckState(0).ToString();
//獲取某項綁定值 valueMember
string trueValue = checkedListBoxControl1.GetItemValue(0).ToString();
//獲取某項顯示值 displayMember
string disValue = checkedListBoxControl1.GetDisplayItemValue(0).ToString();
string disValue2 = checkedListBoxControl1.GetItemText(0);
//是否點擊一次 就改變狀態
checkedListBoxControl1.CheckOnClick = true;
//是否多列顯示
checkedListBoxControl1.MultiColumn = true;
//checkedListboxControl 是否得到焦點
bool isfocus=checkedListBoxControl1.ContainsFocus;
//實現單選功能
checkedListBoxControl1.SelectedIndexChanged += new EventHandler(checkedListBoxControl1_SelectedIndexChanged);
//獲取選中項的綁定值(前提:手動添加的能夠獲取,可是datatable綁定的沒法獲取)
List<object> objList = checkedListBoxControl1.Items.GetCheckedValues();
void checkedListBoxControl1_SelectedIndexChanged(object sender, EventArgs e)
{
int index=checkedListBoxControl1.SelectedIndex;
for (int i = 0; i < checkedListBoxControl1.ItemCount; i++) {
if (i != index)
{
checkedListBoxControl1.SetItemChecked(i, false);
}
}
}
#region public static void SetComboBoxData(DevExpress.XtraEditors.ImageComboBoxEdit comboBox,List<T> list, string valueMember, string displayMember, string selectedText = null) /// <summary> /// 綁定下拉框 /// </summary> /// <param name="comboBox">下拉控件</param> /// <param name="List<T> ">實體集合</param> /// <param name="valueMember">值字段</param> /// <param name="displayMember">顯示字段</param> /// <param name="selectedText">默認選中的值</param> public static void SetComboBoxData<T>(DevExpress.XtraEditors.ImageComboBoxEdit comboBox, List<T> list, string valueMember, string displayMember, string selectedText = null)// { comboBox.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; comboBox.Properties.NullText = string.Empty; foreach (var item in list) { comboBox.Properties.Items.Add(new ImageComboBoxItem(item.GetType().GetProperty(valueMember).GetValue(item, null).ToString(), item.GetType().GetProperty(valueMember).GetValue(item, null).ToString())); } // //這裏是設置默認選中的值 if (!string.IsNullOrEmpty(selectedText)) { comboBox.SelectedItem = comboBox.Properties.Items.GetItem(selectedText); } } #endregion
http://www.cnblogs.com/spring_wang/archive/2013/05/11/3072640.html
https://blog.csdn.net/xiaoyu812289718/article/details/43017755
https://blog.csdn.net/u013816709/article/details/48159309