This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
MultiSelectColumnCustomizationListBox.vb
101 lines (86 loc) · 3.18 KB
/
MultiSelectColumnCustomizationListBox.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.Utils.Drawing
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid.Customization
Namespace MultiSelectColumnCustomization
Public Class MultiSelectColumnCustomizationListBox
Inherits ColumnCustomizationListBox
Private pushedIndex As Integer = -1
Private ReadOnly checkedItems_Renamed As New List(Of Object)()
Private focusedItem As Object = Nothing
Public Sub New(ByVal form As CustomizationForm)
MyBase.New(form)
End Sub
Protected Overrides Sub DrawItemObject(ByVal cache As GraphicsCache, ByVal index As Integer, ByVal bounds As Rectangle, ByVal itemState As DrawItemState)
If index = pushedIndex Then
CType(Items(index), GridColumn).Tag = 2
Else
CType(Items(index), GridColumn).Tag = 0
End If
If checkedItems_Renamed.Contains(Items(index)) Then
CType(Items(index), GridColumn).Tag = 1
End If
MyBase.DrawItemObject(cache, index, bounds, itemState)
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
Dim mousePoint As New Point(e.X, e.Y)
Dim pointedItem As Object = ItemByPoint(New Point(e.X, e.Y))
Dim itemIndex As Integer = Items.IndexOf(pointedItem)
Dim itemRect As Rectangle = GetItemRectangle(itemIndex)
If e.Button = MouseButtons.Left Then
pushedIndex = itemIndex
Me.InvalidateObject(pointedItem)
Return
End If
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
Dim mousePoint As New Point(e.X, e.Y)
Dim pointedItem As Object = ItemByPoint(New Point(e.X, e.Y))
Dim itemIndex As Integer = Items.IndexOf(pointedItem)
Dim itemRect As Rectangle = GetItemRectangle(itemIndex)
If e.Button = MouseButtons.Left Then
If ModifierKeys = Keys.Shift Then
Dim startIndex As Integer = Items.IndexOf(focusedItem)
Dim endIndex As Integer = Items.IndexOf(pointedItem)
Dim check As Boolean = Not checkedItems_Renamed.Contains(pointedItem)
If endIndex >= startIndex Then
For i As Integer = startIndex To endIndex
If check AndAlso (Not checkedItems_Renamed.Contains(Items(i))) Then
checkedItems_Renamed.Add(Items(i))
ElseIf (Not check) AndAlso checkedItems_Renamed.Contains(Items(i)) Then
checkedItems_Renamed.Remove(Items(i))
End If
Next i
Else
For i As Integer = endIndex To startIndex - 1
If check AndAlso (Not checkedItems_Renamed.Contains(Items(i))) Then
checkedItems_Renamed.Add(Items(i))
ElseIf (Not check) AndAlso checkedItems_Renamed.Contains(Items(i)) Then
checkedItems_Renamed.Remove(Items(i))
End If
Next i
End If
ElseIf ModifierKeys = Keys.None Then
If checkedItems_Renamed.Contains(pointedItem) Then
checkedItems_Renamed.Remove(pointedItem)
Else
checkedItems_Renamed.Add(pointedItem)
End If
End If
focusedItem = pointedItem
pushedIndex = -1
Me.InvalidateObject(pointedItem)
Return
End If
End Sub
Public ReadOnly Property CheckedItems() As List(Of Object)
Get
Return checkedItems_Renamed
End Get
End Property
End Class
End Namespace