public bool IsSelected(TreeNode tn) { Guid id; NodeGuidDictionary.TryGetValue(tn, out id); return(IsSelected(id)); }
private void AddEventHandlers() { ViewTreeLink.LinkClicked += delegate { ViewTree(); }; ViewSearchLink.LinkClicked += delegate { ViewSearchResults(); }; Results.MouseDown += delegate(object sender, MouseEventArgs e) { ListViewItem item = Results.HitTest(e.X, e.Y).Item; if (item != null) { if (Results.HitTest(e.X, e.Y).Location == ListViewHitTestLocations.Image) { string name = item.Text; var id = new Guid(item.SubItems[2].Text); var taxonomy = new TaxonomyStruct { Name = name, ID = id }; AddToSelected(taxonomy); } if (Results.HitTest(e.X, e.Y).SubItem == item.SubItems[1]) //if mouse click on "view in tree" { TreeNode node; GuidNodeDictionary.TryGetValue(new Guid(item.SubItems[2].Text), out node); ViewTree(); ExpandTreeTo(node); } } }; Results.ItemSelectionChanged += delegate(object sender, ListViewItemSelectionChangedEventArgs e) { foreach (ListViewItem i in Results.Items) { if (i != e.Item) { i.BackColor = Color.Empty; i.Selected = false; } } //e.Item.Selected = true; //e.Item.BackColor = Color.Yellow; }; Results.MouseMove += delegate(object sender, MouseEventArgs e) { ListViewItem item = Results.HitTest(e.X, e.Y).Item; if (item != null) { if (Results.HitTest(e.X, e.Y).SubItem == item.SubItems[1] || Results.HitTest(e.X, e.Y).Location == ListViewHitTestLocations.Image) { Cursor.Current = Cursors.Hand; } } }; Selected.MouseDown += delegate(object sender, MouseEventArgs e) { ListViewItem item = Selected.HitTest(e.X, e.Y).Item; if (Selected.HitTest(e.X, e.Y).Location == ListViewHitTestLocations.Image) { string name = item.Text; var id = new Guid(item.SubItems[1].Text); var taxonomy = new TaxonomyStruct { Name = name, ID = id }; RemoveFromSelected(taxonomy); } }; Keywords.KeyDown += delegate(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Up) { if (Results.SelectedItems.Count != 0) { int index = Results.SelectedIndices[0]; if (index > 0) { Results.Items[index].Selected = false; Results.Items[index].BackColor = Color.Empty; Results.Items[index - 1].Selected = true; Results.Items[index - 1].BackColor = Color.Yellow; } } } if (e.KeyCode == Keys.Down) { if (Results.SelectedItems.Count != 0) { int index = Results.SelectedIndices[0]; if (index < Results.Items.Count - 1) { Results.Items[index].Selected = false; Results.Items[index].BackColor = Color.Empty; Results.Items[index + 1].Selected = true; Results.Items[index + 1].BackColor = Color.Yellow; } } } if (e.KeyCode == Keys.Enter) { if (Results.SelectedItems.Count == 0) { PopulateResults(); ViewSearchResults(); } else { string name = Results.SelectedItems[0].Text; Guid guid = new Guid(Results.SelectedItems[0].SubItems[2].Text); TaxonomyStruct ts = new TaxonomyStruct { ID = guid, Name = name }; if (!AddToSelected(ts)) { RemoveFromSelected(ts); } Keywords.Text = ""; } } }; Keywords.TextChanged += delegate { if (Keywords.TextLength > 1) { PopulateResults(); ViewSearchResults(); if (Results.Items.Count > 0) { Results.Items[0].BackColor = Color.Yellow; Results.Items[0].Selected = true; } } }; ResultsTree.MouseDown += delegate(object sender, MouseEventArgs e) { if (ResultsTree.HitTest(e.X, e.Y).Location == TreeViewHitTestLocations.Image) { TreeNode node = ResultsTree.HitTest(e.X, e.Y).Node; string name = node.Text; Guid id; NodeGuidDictionary.TryGetValue(node, out id); var ts = new TaxonomyStruct { Name = name, ID = id }; AddToSelected(ts); } }; }