private void ComboBoxReasonTextUpdate(object sender, EventArgs e) { _filterString = comboBoxReason.Text; if (string.IsNullOrEmpty(_filterString)) { UpdateItems(); } else { comboBoxReason.Items.Clear(); comboBoxReason.Items.Add("N/A"); if (_typeItemsCollection != null) { foreach (BaseEntityObject dic in _typeItemsCollection .OfType <BaseEntityObject>() .Where(i => i.ToString().ToLowerInvariant().Contains( _filterString.ToLowerInvariant()))) { comboBoxReason.Items.Add(dic); } } comboBoxReason.DropDownStyle = ComboBoxStyle.DropDown; comboBoxReason.SelectionStart = _filterString.Length; } }
/// <summary> /// Обновляет значения полей /// </summary> public override void FillControls() { BeginUpdate(); if (_typeItemsCollection != null) { _typeItemsCollection.CollectionChanged -= DictionaryCollectionChanged; } checkedListBoxItems.Items.Clear(); checkedListBoxItems.SelectedIndexChanged -= CheckedListBoxItemsSelectedIndexChanged; checkBoxSelectAll.CheckedChanged -= CheckBoxSelectAllCheckedChanged; if (Filter != null) { Type filterType = Filter.GetType(); if (filterType.IsGenericType) { Type genericArgumentType = filterType.GetGenericArguments().FirstOrDefault(); if (genericArgumentType.IsSubclassOf(typeof(AbstractDictionary))) { try { if (GlobalObjects.CasEnvironment != null) { _typeItemsCollection = GlobalObjects.CasEnvironment.GetDictionary(genericArgumentType); } else { _typeItemsCollection = GlobalObjects.CaaEnvironment.GetDictionary(genericArgumentType); } } catch (Exception) { _typeItemsCollection = null; } } if (genericArgumentType.IsSubclassOf(typeof(StaticDictionary))) { try { PropertyInfo p = genericArgumentType.GetProperty("Items"); ConstructorInfo ci = genericArgumentType.GetConstructor(new Type[0]); StaticDictionary instance = (StaticDictionary)ci.Invoke(null); _typeItemsCollection = (IDictionaryCollection)p.GetValue(instance, null); } catch (Exception) { _typeItemsCollection = null; } } } if (_typeItemsCollection != null) { //в CheckListBox добавляются только элементы используемые в фильтруемых //объектах if (_filterValues != null && _filterValues.Length > 0) { foreach (IDictionaryItem dic in _typeItemsCollection.OfType <IDictionaryItem>().Where(i => _filterValues.Contains(i))) { checkedListBoxItems.Items.Add(dic, Filter.Values.Contains(dic)); } int countValidItems = Filter.GetValidValuesCount(); if (countValidItems == 0) { checkBoxSelectAll.CheckState = CheckState.Unchecked; } else if (countValidItems == _filterValues.Length) { checkBoxSelectAll.CheckState = CheckState.Checked; } else { checkBoxSelectAll.CheckState = CheckState.Indeterminate; } } } } checkedListBoxItems.SelectedIndexChanged += CheckedListBoxItemsSelectedIndexChanged; checkBoxSelectAll.CheckedChanged += CheckBoxSelectAllCheckedChanged; if (_typeItemsCollection != null) { _typeItemsCollection.CollectionChanged += DictionaryCollectionChanged; } EndUpdate(); }
private void ComboBoxReasonTextUpdate(object sender, EventArgs e) { _filterString = treeCombobox.Text; if (string.IsNullOrEmpty(_filterString)) { UpdateItems(); } else { treeCombobox.Nodes.Clear(); treeCombobox.Nodes.Add("N/A"); if (_typeItemsCollection != null) { try { if (_type.IsSubclassOf(typeof(StaticTreeDictionary))) { if (_rootNodesNames == null || _rootNodesNames.Length <= 0) { //поиск своиства Roots у типа StaticDictionary PropertyInfo p = _type.GetProperty("Items"); ConstructorInfo ci = _type.GetConstructor(new Type[0]); StaticDictionary instance = (StaticDictionary)ci.Invoke(null); IDictionaryCollection items = (IDictionaryCollection)p.GetValue(instance, null); foreach (IDictionaryTreeItem dic in items .OfType <IDictionaryTreeItem>() .Where(i => i.ToString().ToLowerInvariant().Contains(_filterString.ToLowerInvariant()))) { treeCombobox.Nodes.Add(new TreeNode { Text = dic.ToString(), Name = dic.ToString(), Tag = dic }); } buttonEdit.Enabled = false; } else { ConstructorInfo ci = _type.GetConstructor(new Type[0]); object instance = ci.Invoke(null); foreach (string rootNodeName in _rootNodesNames) { //поиск своиства Roots у типа StaticDictionary FieldInfo p = _type.GetField(rootNodeName); if (p == null) { continue; } StaticTreeDictionary currentRoot = p.GetValue(instance) as StaticTreeDictionary; StaticTreeDictionary currentNode = currentRoot; if (currentNode == null) { return; } while (currentNode != null) { if (currentNode.ToString().ToLowerInvariant().Contains(_filterString.ToLowerInvariant())) { TreeNode newNode = new TreeNode { Text = currentNode.ToString(), Name = currentNode.ToString(), Tag = currentNode, }; Nodes.Add(newNode); } if (currentNode.Children.Count > 0) { //Если у выбранного узла есть подузлы - осуществляется переход на первый подузел currentNode = currentNode.Children[0] as StaticTreeDictionary; } else { //У выбранного узла подузлов нет if (currentNode.Next != null) { //Если есть след. узел на этом уровне - переход на него currentNode = currentNode.Next; } else { //На данном уровне след. узла нет. StaticTreeDictionary parent = currentNode.Parent; while (parent != null && parent != currentRoot) { //Переход вверх по дереву до тех пор, пока на уровне не появится след.узел //переход на след. узел на верхнем уровне if (parent.Next != null) { currentNode = parent.Next; break; } parent = parent.Parent; } if (parent == null || parent == currentRoot) { currentNode = null; } } } } } } } if (_type.IsSubclassOf(typeof(AbstractDictionary))) { foreach (IDictionaryItem dic in _typeItemsCollection) { treeCombobox.Nodes.Add(new TreeNode { Text = dic.ToString(), Tag = dic }); } } } catch (Exception) { _typeItemsCollection = null; } } treeCombobox.DropDownStyle = ComboBoxStyle.DropDown; treeCombobox.SelectionStart = _filterString.Length; } }