GUI/Controls/TreeViewWithSearchResults.cs
/// <summary>
/// When the user clicks in the ListView, check if the user clicks outside of a ListViewItem. If so, de-select any previously selected ListViewItems. In addition,
/// if the user right clicked an item in the ListView, let our subscribers know what was clicked and where in case a context menu is needed to be shown.
/// </summary>
/// <param name="sender">Object which raised event.</param>
/// <param name="e">Event data.</param>
When the user clicks in the ListView, check if the user clicks outside of a ListViewItem. If so, de-select any previously selected ListViewItems. In addition,
if the user right clicked an item in the ListView, let our subscribers know what was clicked and where in case a context menu is needed to be shown.
When the user clicks in the ListView check if the user clicks outside of a ListViewItem . If so de - select any previously selected ListViewItems . In addition if the user right clicked an item in the ListView let our subscribers know what was clicked and where in case a context menu is needed to be shown .
private void MainListView_MouseDown(object sender, MouseEventArgs e)
        {
            var info = mainListView.HitTest(e.X, e.Y);
            if (info.Item != null)
            {
                if (e.Button == MouseButtons.Right)
                {
                    ListViewItemRightClick?.Invoke(sender, new ListViewItemClickEventArgs(info.Item, e.Location));
                }
                else if (e.Button == MouseButtons.Left)
                {
                    var node = info.Item.Tag as TreeNode;
                    if (node.Tag is TreeViewFolder)
                    {
                        node.EnsureVisible();
                        node.TreeView.SelectedNode = node;
                    }
                }
            }
            else
            {
                mainListView.SelectedItems.Clear();
            }
        }
private void MainListView_MouseDown ( object sender , MouseEventArgs e ) { var info = mainListView . HitTest ( e . X , e . Y ) ; if ( info . Item != null ) { if ( e . Button == MouseButtons . Right ) { ListViewItemRightClick ? . Invoke ( sender , new ListViewItemClickEventArgs ( info . Item , e . Location ) ) ; } else if ( e . Button == MouseButtons . Left ) { var node = info . Item . Tag as TreeNode ; if ( node . Tag is TreeViewFolder ) { node . EnsureVisible ( ) ; node . TreeView . SelectedNode = node ; } } } else { mainListView . SelectedItems . Clear ( ) ; } }
When the user clicks in the ListView, check if the user clicks outside of a ListViewItem.
When the user clicks in the ListView check if the user clicks outside of a ListViewItem .
// if an item was clicked in the list view // right click should just notify our subscribers // left click should focus the node in its tree view
sender
object
Object which raised event.
Object which raised event .
e
MouseEventArgs
None