Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
185
UltraWinListView right click not selectnig items
posted

Unlike Windows Explorer, your latest FileExplorer sample does not select the item underneath the mouse when right clicking for a context menu.  I can't see a way to do this.  Is it possible to do without extra form code? This used to be a problem in VB6 with the Microsoft ListView but was fixed.

Thanks
Mark Treveil
 

  • 69832
    Offline posted

    No, it is not possible to select items on a right-click without extra form code.

    The following code sample demonstrates how to use the SelectedItems collection to programmatically select items, in this case in response to the pressing of the right mouse button:

    /// <summary>
    /// Handles the UltraListView's MouseDown event.
    /// </summary>
    private void UltraListView_MouseDown(object sender, MouseEventArgs e)
    {
        if ( e.Button == MouseButtons.Right )
        {
            UltraListView listView = sender as UltraListView;

            if ( listView != null )
            {
                UltraListViewItem itemAtPoint = listView.ItemFromPoint( e.Location );
                if ( itemAtPoint != null )
                {
                    bool controlKeyDown = (Control.ModifierKeys & Keys.Control) == Keys.Control;
                    listView.SelectedItems.Add( itemAtPoint, controlKeyDown == false );
                }
            }
        }
    }