Skip to main content Skip to footer

HowTo: Select Items with LeftMouseButton in C1TileListBox

The C1TileListBox for WPF provides the functionality to select and deselect Items by default at the RightMouse button's click. This blog explains an approach to select and deselect items at the LeftMouse button's click. TileListBox_LeftMouseBtn To implement the same, we will make use of its MouseLeftButtonUp and PreviewMouseRightButtonDown events.

Implement the functionality at the LeftMouseButton click

Private Sub tileListBox_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) Handles tileListBox.MouseLeftButtonUp  
 Dim index As Integer = tileListBox.GetIndexAt(e.GetPosition(tileListBox))  
 Dim obj As Item = CType(tileListBox.Items(index), Item)  

Dim lst As List(Of Object) = CType(tileListBox.SelectedItems, Object()).ToList()  

If Keyboard.IsKeyDown(Key.LeftCtrl) Or Keyboard.IsKeyDown(Key.RightCtrl) Then  
 flag = True  
 If flag = True Then  
 flag = False  
 End If  
 End If  
 tileListBox.SelectedItems = lst.ToArray()  
 End Sub  

Handle the behaviour at RightMouseButton Click

Private Sub tileListBox_PreviewMouseRightButtonDown(sender As Object, e As MouseButtonEventArgs) Handles tileListBox.PreviewMouseRightButtonDown  
 e.Handled = True  
 End Sub  

Download Sample CS Download Sample VB


comments powered by Disqus