Multiselect

This commit is contained in:
Jonathan Jenne
2023-08-02 08:11:40 +02:00
parent 5cb526e7a4
commit 080a711067
10 changed files with 634 additions and 421 deletions

View File

@@ -0,0 +1,103 @@
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.XtraTreeList.Nodes.Operations
Public Class ClassTreeListViewState
Private expanded As ArrayList
Private selected As ArrayList
Private focused As Object
Private topNode As Object
Public Sub New()
Me.New(Nothing)
End Sub
Public Sub New(ByVal treeList As TreeList)
Me.treeList_Renamed = treeList
expanded = New ArrayList()
selected = New ArrayList()
End Sub
Public Sub Clear()
expanded.Clear()
selected.Clear()
focused = Nothing
topNode = Nothing
End Sub
Private Function GetExpanded() As ArrayList
Dim op As New OperationSaveExpanded()
TreeList.NodesIterator.DoOperation(op)
Return op.Nodes
End Function
Private Function GetSelected() As ArrayList
Dim al As New ArrayList()
For Each node As TreeListNode In TreeList.Selection
al.Add(node.GetValue(TreeList.KeyFieldName))
Next node
Return al
End Function
Public Sub LoadState()
TreeList.BeginUpdate()
Try
TreeList.CollapseAll()
Dim node As TreeListNode
For Each key As Object In expanded
node = TreeList.FindNodeByKeyID(key)
If node IsNot Nothing Then
node.Expanded = True
End If
Next key
TreeList.FocusedNode = TreeList.FindNodeByKeyID(focused)
For Each key As Object In selected
node = TreeList.FindNodeByKeyID(key)
If node IsNot Nothing Then
TreeList.Selection.Add(node)
End If
Next key
Finally
TreeList.EndUpdate()
Dim topVisibleNode As TreeListNode = TreeList.FindNodeByKeyID(topNode)
If topVisibleNode Is Nothing Then
topVisibleNode = TreeList.FocusedNode
End If
TreeList.TopVisibleNodeIndex = TreeList.GetVisibleIndexByNode(topVisibleNode)
End Try
End Sub
Public Sub SaveState()
If TreeList.FocusedNode IsNot Nothing Then
expanded = GetExpanded()
selected = GetSelected()
focused = TreeList.FocusedNode(TreeList.KeyFieldName)
topNode = TreeList.GetNodeByVisibleIndex(TreeList.TopVisibleNodeIndex)(TreeList.KeyFieldName)
Else
Clear()
End If
End Sub
Private treeList_Renamed As TreeList
Public Property TreeList() As TreeList
Get
Return treeList_Renamed
End Get
Set(ByVal value As TreeList)
treeList_Renamed = value
Clear()
End Set
End Property
Private Class OperationSaveExpanded
Inherits TreeListOperation
Private al As New ArrayList()
Public Overrides Sub Execute(ByVal node As TreeListNode)
If node.HasChildren AndAlso node.Expanded Then
al.Add(node.GetValue(node.TreeList.KeyFieldName))
End If
End Sub
Public ReadOnly Property Nodes() As ArrayList
Get
Return al
End Get
End Property
End Class
End Class

View File

@@ -8,6 +8,35 @@ Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraEditors.Controls
Public Class ClassWindreamDocGrid
' === BEGIN CLASS PART ===
Public Class WindreamDoc
Public Property DocId As Integer
Public Property DocPath As String
Public Property DisplayName As String
Public Property DocType As String
End Class
Private ReadOnly GridView As GridView
Public ReadOnly Property SelectedDocuments As List(Of WindreamDoc)
Get
Return GetSelectedDocuments(GridView)
End Get
End Property
Public ReadOnly Property HasSelectedDocuments As Boolean
Get
Return HasNoSelectedDocuments(GridView)
End Get
End Property
Public Sub New(pGridView As GridView)
GridView = pGridView
End Sub
' === END CLASS PART ===
Private Shared _Helper As ClassHelper
Public Shared SELECTED_DOC_PATH As String
'Public Shared RESULT_OBJECTTYPE As String
@@ -31,12 +60,6 @@ Public Class ClassWindreamDocGrid
Private Shared _textValueChangedHandler As EventHandler
Private Shared _checkValueChangedHandler As EventHandler
Public Class WindreamDoc
Public Property DocId As Integer
Public Property DocPath As String
Public Property DisplayName As String
End Class
Private Shared Function Init_Table()
Try
Dim table As New DataTable With {
@@ -60,7 +83,12 @@ Public Class ClassWindreamDocGrid
End Function
Public Shared Function GetSelectedDocuments(pGridView As GridView)
Public Shared Function HasNoSelectedDocuments(pGridView As GridView) As Boolean
Dim oSelectedRows As List(Of Integer) = pGridView.GetSelectedRows().ToList()
Return oSelectedRows.Count = 0
End Function
Public Shared Function GetSelectedDocuments(pGridView As GridView) As List(Of WindreamDoc)
Dim oSelectedRows As List(Of Integer) = pGridView.GetSelectedRows().ToList()
Dim oDocuments As New List(Of WindreamDoc)
@@ -68,10 +96,12 @@ Public Class ClassWindreamDocGrid
Dim oDocId = pGridView.GetRowCellValue(oRowHandle, "DocID")
Dim oDisplayName = pGridView.GetRowCellValue(oRowHandle, "Displayname")
Dim oDocPath = pGridView.GetRowCellValue(oRowHandle, "FULLPATH")
Dim oDocType = pGridView.GetRowCellValue(oRowHandle, "OBJECTTYPE")
oDocuments.Add(New WindreamDoc With {
.DocId = oDocId,
.DocPath = oDocPath,
.DocType = oDocType,
.DisplayName = oDisplayName
})
Next