public static void RestoreSettingsByName( CheckedListBoxControl c, IPersistentPairStorage storage, string key) { var names = new List <string>(); for (var i = 0; i < c.Items.Count; ++i) { if (c.GetItemChecked(i)) { names.Add(c.GetItem(i).ToString()); } } var def = string.Join(@"###{{{}}}###", names.ToArray()); // -- var s = PersistanceHelper.RestoreValue( storage, key, def) as string; if (string.IsNullOrEmpty(s)) { for (var i = 0; i < c.Items.Count; ++i) { c.SetItemChecked(i, false); } } else { var splitted = new List <string>(s.Split(new[] { @"###{{{}}}###" }, StringSplitOptions.RemoveEmptyEntries)); var ris = new List <string>(splitted); for (var i = 0; i < c.Items.Count; ++i) { c.SetItemChecked(i, ris.Contains(c.GetItem(i).ToString())); } } }
void SetCheckedListBoxChecked(CheckedListBoxControl chkControl, string strCollected) { if (strCollected == null) { return; } string[] array = strCollected.Split(','); for (int i = 0; i < chkControl.Items.Count; i++) { string val = chkControl.GetItemValue(i).ToString(); if (array.Contains(val)) { chkControl.SetItemChecked(i, true); } else { chkControl.SetItemChecked(i, false); } } }
public static void SetCheckedItems(CheckedListBoxControl listBox, StringCollection checkedNames) { for (int i = 0; i < listBox.Items.Count; ++i) { object item = listBox.Items[i]; if ((checkedNames == null) || !checkedNames.Contains(item.ToString())) { if (listBox.GetItemChecked(i)) { listBox.SetItemChecked(i, false); } } else { if (!listBox.GetItemChecked(i)) { listBox.SetItemChecked(i, true); } } } }
/// <summary> /// 加载数据 /// </summary> public void DoLoadData() { _fieldAll = CommonData.GetTableFieldsDef(_tableName, true); _fieldSelected = bllBusinessLog.GetLogFieldDef(_tableName); foreach (DataRow row in _fieldAll.Rows) { string name = row["FieldName"].ToString(); string text = row["DisplayName"].ToString(); string display = name.PadRight(22, char.Parse(" ")) + " - " + text; int i = _fieldList.Items.Add(new ItemObject(display, name)); // false=增加状态 DataRow[] rows = _fieldSelected.Select("FieldName='" + name + "'"); if (rows.Length > 0) { _fieldList.SetItemChecked(i, true); } else { _fieldList.SetItemChecked(i, false); } } }
private void chkStatusType_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) { if (e.State != CheckState.Checked) { return; } CheckedListBoxControl lb = sender as CheckedListBoxControl; for (int i = 0; i < lb.ItemCount; i++) { if (i != e.Index) { lb.SetItemChecked(i, false); } } }
private void CheckUncheckListboxItems(CheckedListBoxControl AListBox, bool ACheckState) { try { for (int i = 0; i < AListBox.ItemCount; i++) { DataRowView row = AListBox.GetItem(i) as DataRowView; AListBox.SetItemChecked(i, ACheckState); } } catch (Exception error) { XtraMessageBox.Show("An error occurred while setting selected preferences to checked/unchecked." + Environment.NewLine + "Error CNF-323 in " + FORM_NAME + ".CheckUncheckListboxItems(): " + error.Message, FORM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CheckUncheckListboxItems(CheckedListBoxControl AListBox, bool ACheckState) { try { for (int i = 0; i < AListBox.ItemCount; i++) { DataRowView row = AListBox.GetItem(i) as DataRowView; AListBox.SetItemChecked(i, ACheckState); } } catch (Exception error) { XtraMessageBox.Show("An error occurred while setting selected preferences to checked/unchecked." + Environment.NewLine + "Error CNF-323 in " + FORM_NAME + ".CheckUncheckListboxItems(): " + error.Message, FORM_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void RestoreSettings( CheckedListBoxControl c, IPersistentPairStorage storage, string key ) { var indexes = new List<string>(); for ( var i = 0; i < c.Items.Count; ++i ) { if ( c.GetItemChecked( i ) ) { indexes.Add( i.ToString() ); } } var def = string.Join( @";", indexes.ToArray() ); // -- var s = PersistanceHelper.RestoreValue( storage, key, def ) as string; if ( string.IsNullOrEmpty( s ) ) { for ( var i = 0; i < c.Items.Count; ++i ) { c.SetItemChecked( i, false ); } } else { var splitted = new List<string>( s.Split( ';' ) ); var ris = new List<int>(); splitted.ForEach( x => ris.Add( int.Parse( x ) ) ); for ( var i = 0; i < c.Items.Count; ++i ) { c.SetItemChecked( i, ris.Contains( i ) ); } } }
private void checkedListCompany_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) { flag = SelectedCompanyType(); Validation(); if (e.State != CheckState.Checked) { return; } CheckedListBoxControl lb = sender as CheckedListBoxControl; for (int i = 0; i < lb.ItemCount; i++) { if (i != e.Index) { lb.SetItemChecked(i, false); } } }
private void settingSecondaryItemListBoxControl_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e) { if (e.Index == 0) { return; } CheckedListBoxControl checkList = sender as CheckedListBoxControl; if (e.Index < checkList.ItemCount - 1 && e.State == CheckState.Unchecked) { if (checkList.GetItemChecked(checkList.ItemCount - 1)) { checkList.SetItemChecked(checkList.ItemCount - 1, false); } } else if (e.Index == checkList.ItemCount - 1) { if (e.State == CheckState.Checked) { checkList.CheckAll(); } else { int checkCount = 0; for (int index = 0; index < checkList.ItemCount - 1; index++) { if (checkList.GetItemChecked(index)) { checkCount++; } if (checkCount == checkList.ItemCount - 1) { checkList.UnCheckAll(); } } } } }
public static void RestoreSettingsByName( CheckedListBoxControl c, IPersistentPairStorage storage, string key ) { var names = new List<string>(); for ( var i = 0; i < c.Items.Count; ++i ) { if ( c.GetItemChecked( i ) ) { names.Add(c.GetItem(i).ToString()); } } var def = string.Join(@"###{{{}}}###", names.ToArray()); // -- var s = PersistanceHelper.RestoreValue( storage, key, def ) as string; if ( string.IsNullOrEmpty( s ) ) { for ( var i = 0; i < c.Items.Count; ++i ) { c.SetItemChecked( i, false ); } } else { var splitted = new List<string>(s.Split(new[] {@"###{{{}}}###"}, StringSplitOptions.RemoveEmptyEntries)); var ris = new List<string>(splitted); for ( var i = 0; i < c.Items.Count; ++i ) { c.SetItemChecked(i, ris.Contains(c.GetItem(i).ToString())); } } }