private void conditionsList_SelectedIndexChanged(object sender, EventArgs e) { if (conditionsList.SelectedItems.Count > 0) { ConditionItem condition = conditionsList.SelectedItems[0].Tag as ConditionItem; conditionProperties.SelectedObject = condition.condition; } else { conditionProperties.SelectedObject = null; } }
private void RefreshConditionsList() { List <ConditionItem> conditions = new List <ConditionItem>(); if (rulesList.SelectedItems.Count > 0) { Rule rule = rulesList.SelectedItems[0].Tag as Rule; if (rule != null) { //Get list of existing conditions foreach (BaseCondition condition in rule.Conditions) { ConditionItem item = new ConditionItem(); item.condition = condition; item.enabled = true; conditions.Add(item); } //Get list of all possible conditions Assembly archiverAssembly = typeof(FreeSCADA.Archiver.ArchiverMain).Assembly; foreach (Type type in archiverAssembly.GetExportedTypes()) { if (type.IsSubclassOf(typeof(BaseCondition))) { bool isExists = false; foreach (ConditionItem item in conditions) { if (item.condition.GetType() == type) { isExists = true; break; } } if (isExists == false) { ConditionItem item = new ConditionItem(); item.condition = (BaseCondition)Activator.CreateInstance(type); item.enabled = false; conditions.Add(item); } } } } } conditionsList.Tag = conditions; //Fill control conditionsList.ItemChecked -= new System.Windows.Forms.ItemCheckedEventHandler(conditionsList_ItemChecked); ListView.SelectedIndexCollection selected = conditionsList.SelectedIndices; conditionsList.Items.Clear(); for (int i = 0; i < conditions.Count; i++) { ConditionItem condition = conditions[i]; ListViewItem item = conditionsList.Items.Add(condition.condition.Name); item.Tag = condition; item.Checked = condition.enabled; item.Selected = selected.Count > 0 ? selected.Contains(i):false; item.SubItems.Add(condition.condition.Description); } if (conditions.Count > 0) { conditionsList.Columns[0].Width = -2; conditionsList.Columns[1].Width = -2; } conditionsList.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(conditionsList_ItemChecked); }