Note that there are some explanatory texts on larger screens.

plurals
  1. POAllow select items only with right click in ListBox
    primarykey
    data
    text
    <p>I'm still trying to do this. No clue how. I have a ListBox with Drag&amp;Drop to move items and add new. What I'm trying to do is when user clicks on item with left mouse button nothing happens. And when he clicks with right mouse button it selects it (Multiple selection). I have tried <code>e.Handled = true</code>, the problem is that it doesn't allow user to scroll with mouse. My listbox's events:</p> <pre><code> private void LB_SongList_Drop(object sender, DragEventArgs e) { ListBox parent = sender as ListBox; Song data = e.Data.GetData(typeof(Song)) as Song; Song objectToPlaceBefore = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as Song; if (data != null &amp;&amp; objectToPlaceBefore != null) { [...]//Code that moves object parent.SelectedItems.Remove(data); } else { String[] file = e.Data.GetData(DataFormats.FileDrop, true) as String[]; if (file != null) { [...]//Code that adds new data } } } private void LB_SongList_PreviewMouseMove(object sender, MouseEventArgs e) { if (!b_IsScrolling) { if (e.LeftButton == MouseButtonState.Pressed) { MainPointer.Main_AllowClose = false; ListBox parent = sender as ListBox; Song data = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as Song; if (data != null) { parent.SelectedItems.Remove(data); DragDrop.DoDragDrop(parent, data, DragDropEffects.Move); } } } } private static object GetObjectDataFromPoint(ListBox source, Point point) { UIElement element = source.InputHitTest(point) as UIElement; if (element != null) { object data = DependencyProperty.UnsetValue; while (data == DependencyProperty.UnsetValue) { data = source.ItemContainerGenerator.ItemFromContainer(element); if (data == DependencyProperty.UnsetValue) element = VisualTreeHelper.GetParent(element) as UIElement; if (element == source) return null; } if (data != DependencyProperty.UnsetValue) return data; } return null; } private void LB_SongList_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { ListBox parent = sender as ListBox; Song data = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as Song; if (data != null) { LB_SongList.SelectedItems.Remove(data); [...]//Code that plays a song on double click (should allow only left mouse button) } } } private void LB_SongList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (LB_SongList.SelectedItems.Count != 0) { [...] } else { [...] } } </code></pre> <p>Anyone could help with this? Left Mouse button doesn't select any item. Right Mouse Button does select items (Multiple).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload