private void lvwCategories_SelectedIndexChanged(object sender, EventArgs e) { if (lvwCategories.SelectedItems.Count > 0) { try { PerformanceCounter[] pcs; lvwCounters.Items.Clear(); lvwInstances.Items.Clear(); string category = lvwCategories.SelectedItems[0].Text; PerformanceCounterCategory pcCat = new PerformanceCounterCategory(category, txtComputer.Text); string instanceName = ""; if (pcCat.CategoryType == PerformanceCounterCategoryType.MultiInstance) { string[] instances = pcCat.GetInstanceNames(); foreach (string instanceNameItem in (from string s in instances orderby s select s)) { ListViewItem lvi = new ListViewItem(instanceNameItem); if (instanceNameItem.ToLower() == InitialInstance.ToLower()) { lvi.Selected = true; } lvwInstances.Items.Add(lvi); } if (instances.Length > 0) { instanceName = pcCat.GetInstanceNames()[0]; } pcs = pcCat.GetCounters(instanceName); } else { pcs = pcCat.GetCounters(); } foreach (PerformanceCounter pc in (from p in pcs orderby p.CounterName select p)) { ListViewItem lvi = new ListViewItem(pc.CounterName); if (pc.CounterName.ToLower() == InitialCounter.ToLower()) { lvi.Selected = true; } lvwCounters.Items.Add(lvi); } if (lvwInstances.SelectedItems.Count > 0) { lvwInstances.SelectedItems[0].EnsureVisible(); } if (lvwCounters.SelectedItems.Count > 0) { lvwCounters.SelectedItems[0].EnsureVisible(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } CheckForValidCounter(); }
private void lvwCategory_SelectedIndexChanged(object sender, EventArgs e) { if (lvwCategory.SelectedItems.Count > 0) { try { PerformanceCounter[] pcs; List <ListViewItem> lvwInstances = new List <ListViewItem>(); List <ListViewItem> lvwCounters = new List <ListViewItem>(); lvwCounter.Items.Clear(); lvwInstance.Items.Clear(); PerformanceCounterCategory pcCat = new PerformanceCounterCategory(lvwCategory.SelectedItems[0].Text, txtComputer.Text); string instanceName = ""; if (pcCat.CategoryType == PerformanceCounterCategoryType.MultiInstance) { string[] instances = pcCat.GetInstanceNames(); foreach (string instanceNameItem in (from s in instances orderby s select s)) { lvwInstances.Add(new ListViewItem(instanceNameItem)); } lvwInstance.Items.AddRange(lvwInstances.ToArray()); if (instances.Length > 0) { instanceName = pcCat.GetInstanceNames()[0]; } pcs = pcCat.GetCounters(instanceName); } else { pcs = pcCat.GetCounters(); } foreach (PerformanceCounter pc in (from p in pcs orderby p.CounterName select p)) { lvwCounters.Add(new ListViewItem(pc.CounterName)); } lvwCounter.Items.AddRange(lvwCounters.ToArray()); if (InitialCounter != null && InitialCounter.Length > 0) { for (int i = 0; i < lvwCounter.Items.Count; i++) { if (lvwCounter.Items[i].Text.ToLower() == InitialCounter.ToLower()) { lvwCounter.Items[i].Selected = true; lvwCounter.Items[i].EnsureVisible(); break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } CheckForValidCounter(); }
private void cboCategory_SelectedIndexChanged(object sender, EventArgs e) { if (cboCategory.Text.Length > 0) { try { PerformanceCounter[] pcs; cboCounter.Items.Clear(); cboCounter.Text = ""; cboInstance.Items.Clear(); cboInstance.Text = ""; PerformanceCounterCategory pcCat = new PerformanceCounterCategory(cboCategory.Text, txtComputer.Text); string instanceName = ""; if (pcCat.CategoryType == PerformanceCounterCategoryType.MultiInstance) { string[] instances = pcCat.GetInstanceNames(); foreach (string instanceNameItem in instances) { cboInstance.Items.Add(instanceNameItem); } if (instances.Length > 0) { instanceName = pcCat.GetInstanceNames()[0]; } pcs = pcCat.GetCounters(instanceName); } else { pcs = pcCat.GetCounters(); } foreach (PerformanceCounter pc in pcs) { cboCounter.Items.Add(pc.CounterName); } if (InitialCounter != null && InitialCounter.Length > 0) { for (int i = 0; i < cboCounter.Items.Count; i++) { if (cboCounter.Items[i].ToString().ToLower() == InitialCounter.ToLower()) { cboCounter.SelectedIndex = i; break; } } } if (InitialInstance != null && InitialInstance.Length > 0) { for (int i = 0; i < cboInstance.Items.Count; i++) { if (cboInstance.Items[i].ToString().ToLower() == InitialInstance.ToLower()) { cboInstance.SelectedIndex = i; break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } CheckForValidCounter(); }