save expanded group rows at runtime

This commit is contained in:
Jonathan Jenne 2019-05-22 12:27:30 +02:00
parent b1d35c865b
commit 22e570c032
3 changed files with 246 additions and 41 deletions

View File

@ -0,0 +1,209 @@
Imports System
Imports System.Collections
Imports DevExpress.XtraGrid
Imports DevExpress.Utils
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Public Class RefreshHelper
<Serializable>
Public Structure RowInfo
Public Id As Object
Public level As Integer
End Structure
Private view As GridView
Private keyFieldName As String
Private saveExpList_Renamed As ArrayList
Private saveSelList_Renamed As ArrayList
Private saveMasterRowsList_Renamed As ArrayList
Private visibleRowIndex As Integer = -1
Public Sub New(ByVal view As GridView, ByVal keyFieldName As String)
Me.view = view
Me.keyFieldName = keyFieldName
End Sub
Public ReadOnly Property SaveExpList() As ArrayList
Get
If saveExpList_Renamed Is Nothing Then
saveExpList_Renamed = New ArrayList()
End If
Return saveExpList_Renamed
End Get
End Property
Public ReadOnly Property SaveSelList() As ArrayList
Get
If saveSelList_Renamed Is Nothing Then
saveSelList_Renamed = New ArrayList()
End If
Return saveSelList_Renamed
End Get
End Property
Public ReadOnly Property SaveMasterRowsList() As ArrayList
Get
If saveMasterRowsList_Renamed Is Nothing Then
saveMasterRowsList_Renamed = New ArrayList()
End If
Return saveMasterRowsList_Renamed
End Get
End Property
Protected Function FindParentRowHandle(ByVal rowInfo As RowInfo, ByVal rowHandle As Integer) As Integer
Dim result As Integer = view.GetParentRowHandle(rowHandle)
Do While view.GetRowLevel(result) <> rowInfo.level
result = view.GetParentRowHandle(result)
Loop
Return result
End Function
Protected Sub ExpandRowByRowInfo(ByVal rowInfo As RowInfo)
Dim dataRowHandle As Integer = view.LocateByValue(0, view.Columns(keyFieldName), rowInfo.Id)
If dataRowHandle <> GridControl.InvalidRowHandle Then
Dim parentRowHandle As Integer = FindParentRowHandle(rowInfo, dataRowHandle)
view.SetRowExpanded(parentRowHandle, True, False)
End If
End Sub
Protected Function GetRowHandleToSelect(ByVal rowInfo As RowInfo) As Integer
Dim dataRowHandle As Integer = view.LocateByValue(0, view.Columns(keyFieldName), rowInfo.Id)
If dataRowHandle <> GridControl.InvalidRowHandle Then
If view.GetRowLevel(dataRowHandle) <> rowInfo.level Then
Return FindParentRowHandle(rowInfo, dataRowHandle)
End If
End If
Return dataRowHandle
End Function
Protected Sub SelectRowByRowInfo(ByVal rowInfo As RowInfo, ByVal isFocused As Boolean)
If isFocused Then
view.FocusedRowHandle = GetRowHandleToSelect(rowInfo)
Else
view.SelectRow(GetRowHandleToSelect(rowInfo))
End If
End Sub
Public Sub SaveSelectionViewInfo(ByVal list As ArrayList)
list.Clear()
Dim column As GridColumn = view.Columns(keyFieldName)
Dim rowInfo As RowInfo
Dim selectionArray() As Integer = view.GetSelectedRows()
If selectionArray IsNot Nothing Then ' otherwise we have a single focused but not selected row
For i As Integer = 0 To selectionArray.Length - 1
Dim dataRowHandle As Integer = selectionArray(i)
rowInfo.level = view.GetRowLevel(dataRowHandle)
If dataRowHandle < 0 Then ' group row
dataRowHandle = view.GetDataRowHandleByGroupRowHandle(dataRowHandle)
End If
rowInfo.Id = view.GetRowCellValue(dataRowHandle, column)
list.Add(rowInfo)
Next i
End If
rowInfo.Id = view.GetRowCellValue(view.FocusedRowHandle, column)
rowInfo.level = view.GetRowLevel(view.FocusedRowHandle)
list.Add(rowInfo)
End Sub
Public Sub SaveExpansionViewInfo(ByVal list As ArrayList)
If view.GroupedColumns.Count = 0 Then
Return
End If
list.Clear()
Dim column As GridColumn = view.Columns(keyFieldName)
For i As Integer = -1 To Integer.MinValue + 1 Step -1
If Not view.IsValidRowHandle(i) Then
Exit For
End If
If view.GetRowExpanded(i) Then
Dim rowInfo As RowInfo
Dim dataRowHandle As Integer = view.GetDataRowHandleByGroupRowHandle(i)
rowInfo.Id = view.GetRowCellValue(dataRowHandle, column)
rowInfo.level = view.GetRowLevel(i)
list.Add(rowInfo)
End If
Next i
End Sub
Public Sub SaveExpandedMasterRows(ByVal list As ArrayList)
If view.GridControl.Views.Count = 1 Then
Return
End If
list.Clear()
Dim column As GridColumn = view.Columns(keyFieldName)
For i As Integer = 0 To view.DataRowCount - 1
If view.GetMasterRowExpanded(i) Then
list.Add(view.GetRowCellValue(i, column))
End If
Next i
End Sub
Public Sub SaveVisibleIndex()
visibleRowIndex = view.GetVisibleIndex(view.FocusedRowHandle) - view.TopRowIndex
End Sub
Public Sub LoadVisibleIndex()
view.MakeRowVisible(view.FocusedRowHandle, True)
view.TopRowIndex = view.GetVisibleIndex(view.FocusedRowHandle) - visibleRowIndex
End Sub
Public Sub LoadSelectionViewInfo(ByVal list As ArrayList)
view.BeginSelection()
Try
view.ClearSelection()
For i As Integer = 0 To list.Count - 1
SelectRowByRowInfo(DirectCast(list(i), RowInfo), i = list.Count - 1)
Next i
Finally
view.EndSelection()
End Try
End Sub
Public Sub LoadExpansionViewInfo(ByVal list As ArrayList)
If view.GroupedColumns.Count = 0 Then
Return
End If
view.BeginUpdate()
Try
view.CollapseAllGroups()
For Each info As RowInfo In list
ExpandRowByRowInfo(info)
Next info
Finally
view.EndUpdate()
End Try
End Sub
Public Sub LoadExpandedMasterRows(ByVal list As ArrayList)
view.BeginUpdate()
Try
view.CollapseAllDetails()
Dim column As GridColumn = view.Columns(keyFieldName)
For i As Integer = 0 To list.Count - 1
Dim rowHandle As Integer = view.LocateByValue(0, column, list(i))
view.SetMasterRowExpanded(rowHandle, True)
Next i
Finally
view.EndUpdate()
End Try
End Sub
Public Sub SaveViewInfo()
SaveExpandedMasterRows(SaveMasterRowsList)
SaveExpansionViewInfo(SaveExpList)
SaveSelectionViewInfo(SaveSelList)
SaveVisibleIndex()
End Sub
Public Sub LoadViewInfo()
LoadExpandedMasterRows(SaveMasterRowsList)
LoadExpansionViewInfo(SaveExpList)
LoadSelectionViewInfo(SaveSelList)
LoadVisibleIndex()
End Sub
End Class

View File

@ -214,6 +214,7 @@
<Compile Include="ClassFinalizeDoc.vb" /> <Compile Include="ClassFinalizeDoc.vb" />
<Compile Include="ClassIndexListConverter.vb" /> <Compile Include="ClassIndexListConverter.vb" />
<Compile Include="ClassInit.vb" /> <Compile Include="ClassInit.vb" />
<Compile Include="ClassRefreshHelper.vb" />
<Compile Include="ClassRegexEditor.vb" /> <Compile Include="ClassRegexEditor.vb" />
<Compile Include="ClassSQLEditor.vb" /> <Compile Include="ClassSQLEditor.vb" />
<Compile Include="ClassSQLTypeConverter.vb" /> <Compile Include="ClassSQLTypeConverter.vb" />

View File

@ -24,6 +24,8 @@ Public Class frmMain
Private GRID_LOAD_TYPE As String = "OVERVIEW" Private GRID_LOAD_TYPE As String = "OVERVIEW"
Private GRID_INV_COL_REMOVED As Boolean = False Private GRID_INV_COL_REMOVED As Boolean = False
Private NO_WORKFLOWITEMS As Boolean = False Private NO_WORKFLOWITEMS As Boolean = False
Private RefreshHelper As RefreshHelper
Dim DT_CHARTS As DataTable Dim DT_CHARTS As DataTable
'Private _windream As New ClassWindream_allgemein 'Private _windream As New ClassWindream_allgemein
@ -72,6 +74,9 @@ Public Class frmMain
End Try End Try
' Create helper to save/load expanded GroupColumns at runtime
RefreshHelper = New RefreshHelper(GridView_Docs, "GUID")
tslblVersion.Text = String.Format("Version {0}", My.Application.Info.Version.ToString) tslblVersion.Text = String.Format("Version {0}", My.Application.Info.Version.ToString)
If ERROR_STATE = "NO DB-CONNECTION" Or ERROR_STATE = "FAILED DBCONNECTION" Then If ERROR_STATE = "NO DB-CONNECTION" Or ERROR_STATE = "FAILED DBCONNECTION" Then
MsgBox("Bitte hinterlegen Sie die Datenbankverbindung in der Konfiguration!", MsgBoxStyle.Critical, "Fehlende Konfiguration:") MsgBox("Bitte hinterlegen Sie die Datenbankverbindung in der Konfiguration!", MsgBoxStyle.Critical, "Fehlende Konfiguration:")
@ -798,22 +803,23 @@ Public Class frmMain
End Sub End Sub
Private Sub NotifyIcon1_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick Private Sub NotifyIcon1_MouseDoubleClick(sender As System.Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.BringToFront() BringToFront()
Me.Visible = True Visible = True
End Sub End Sub
Private Sub Timer_Tick(sender As System.Object, e As System.EventArgs) Handles TimerRefresh.Tick Private Sub Timer_Tick(sender As System.Object, e As EventArgs) Handles TimerRefresh.Tick
RefreshHelper.SaveViewInfo()
SaveGridLayout() SaveGridLayout()
Load_Profile_items() Load_Profile_items()
Decide_Load() Decide_Load()
tsslblLastSysnc.Text = "Letzte Synchronisation: " & Now.ToLongTimeString tsslblLastSysnc.Text = "Letzte Synchronisation: " & Now.ToLongTimeString
RefreshHelper.LoadViewInfo()
End Sub End Sub
Private Sub NotifyIcon1_Click(sender As System.Object, e As System.EventArgs) Handles NotifyIcon1.Click Private Sub NotifyIcon1_Click(sender As System.Object, e As EventArgs) Handles NotifyIcon1.Click
Me.BringToFront() BringToFront()
Me.Visible = True Visible = True
End Sub End Sub
Private Sub Decide_Load() Private Sub Decide_Load()
Try Try
@ -836,7 +842,7 @@ Public Class frmMain
TimerRefresh.Start() TimerRefresh.Start()
End If End If
End Sub End Sub
Private Sub ToolStripButton2_Click(sender As System.Object, e As System.EventArgs) Handles tstrpbtn_Config.Click Private Sub ToolStripButton2_Click(sender As System.Object, e As EventArgs) Handles tstrpbtn_Config.Click
Dim AdminSecurity As Boolean = False Dim AdminSecurity As Boolean = False
AdminSecurity = TBPM_KONFIGURATIONTableAdapter.cmdGetAdminSecurity() AdminSecurity = TBPM_KONFIGURATIONTableAdapter.cmdGetAdminSecurity()
If AdminSecurity = True Then If AdminSecurity = True Then
@ -848,9 +854,11 @@ Public Class frmMain
End Sub End Sub
Private Sub ToolStripButton2_Click_1(sender As Object, e As EventArgs) Handles tsbtnrefresh.Click Private Sub ToolStripButton2_Click_1(sender As Object, e As EventArgs) Handles tsbtnrefresh.Click
RefreshHelper.SaveViewInfo()
SaveGridLayout() SaveGridLayout()
Load_Profile_items() Load_Profile_items()
Decide_Load() Decide_Load()
RefreshHelper.LoadViewInfo()
End Sub End Sub
Private Sub ToolStripButton2_Click_2(sender As Object, e As EventArgs) Private Sub ToolStripButton2_Click_2(sender As Object, e As EventArgs)
@ -884,9 +892,6 @@ Public Class frmMain
If PROFILE_COUNT > 0 Then NotifyIcon1.ShowBalloonTip(30000, "ProcessManager-Reminder", "Sie haben unerledigte Dokumente in Ihrem Verantwortungsbereich.", ToolTipIcon.Info) If PROFILE_COUNT > 0 Then NotifyIcon1.ShowBalloonTip(30000, "ProcessManager-Reminder", "Sie haben unerledigte Dokumente in Ihrem Verantwortungsbereich.", ToolTipIcon.Info)
End Sub End Sub
Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
End Sub
Sub Load_Profil_from_Grid(ID As Integer) Sub Load_Profil_from_Grid(ID As Integer)
Try Try
@ -1126,6 +1131,7 @@ Public Class frmMain
' und GRID_LOAD_TYPE gesetzt wird. ' und GRID_LOAD_TYPE gesetzt wird.
SaveGridLayout() SaveGridLayout()
Load_Grid_Overview() Load_Grid_Overview()
RefreshHelper.LoadViewInfo()
End Sub End Sub
Sub Load_Grid_Overview() Sub Load_Grid_Overview()
SplitContainerDashboard.Visible = False SplitContainerDashboard.Visible = False
@ -1310,12 +1316,8 @@ Public Class frmMain
grid_column.Dispose() grid_column.Dispose()
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex) LOGGER.Error(ex)
End Try End Try
End If End If
End If End If
Next Next
Catch ex As Exception Catch ex As Exception
@ -1323,9 +1325,6 @@ Public Class frmMain
LOGGER.Info("Unexpected Error in Checking ColumnsGrid: " & ex.Message) LOGGER.Info("Unexpected Error in Checking ColumnsGrid: " & ex.Message)
End Try End Try
'GridView_Docs.SaveLayoutToXml(GetXML_LayoutName())
SaveGridLayout() SaveGridLayout()
If GridView_Docs.Columns.Count <= 2 Then If GridView_Docs.Columns.Count <= 2 Then
LOGGER.Info("GridView_Docs.Columns.Count <= 2 - Reset_Gridlayout will be forced...", False) LOGGER.Info("GridView_Docs.Columns.Count <= 2 - Reset_Gridlayout will be forced...", False)
@ -1346,18 +1345,12 @@ Public Class frmMain
End Try End Try
End If End If
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex) LOGGER.Error(ex)
LOGGER.Info("Load_Grid_Overview - Fehler: " & ex.Message) LOGGER.Info("Load_Grid_Overview - Fehler: " & ex.Message)
MsgBox("Fehler Load_Grid_Overview - Fehler: " & vbNewLine & ex.Message, MsgBoxStyle.Critical, "Achtung:") MsgBox("Fehler Load_Grid_Overview - Fehler: " & vbNewLine & ex.Message, MsgBoxStyle.Critical, "Achtung:")
End Try End Try
Cursor = Cursors.Default Cursor = Cursors.Default
End Sub End Sub
Private Sub tsmiValidationProfil_Click(sender As Object, e As EventArgs) Handles tsmiValidationProfil.Click Private Sub tsmiValidationProfil_Click(sender As Object, e As EventArgs) Handles tsmiValidationProfil.Click
@ -1380,6 +1373,8 @@ Public Class frmMain
End Sub End Sub
Sub Reset_GridLayout() Sub Reset_GridLayout()
RefreshHelper.SaveViewInfo()
' Layout zurücksetzen ' Layout zurücksetzen
ResetLayout() ResetLayout()
SaveGridLayout() SaveGridLayout()
@ -1387,6 +1382,8 @@ Public Class frmMain
' Ansicht neu laden ' Ansicht neu laden
Load_Profile_items() Load_Profile_items()
Decide_Load() Decide_Load()
RefreshHelper.LoadViewInfo()
End Sub End Sub
@ -1474,19 +1471,18 @@ Public Class frmMain
Dim hi As GridHitInfo = view.CalcHitInfo(e.Location) Dim hi As GridHitInfo = view.CalcHitInfo(e.Location)
Dim groupRowButtonClicked = (hi.HitTest = GridHitTest.RowGroupButton) Dim groupRowButtonClicked = (hi.HitTest = GridHitTest.RowGroupButton)
GridCursorLocation = e.Location GridCursorLocation = e.Location
' wenn in eine Group Row Doppelt geklickt wurde..
If hi.InGroupRow And Not groupRowButtonClicked Then
' Ein/Ausklappen verhindern
DXMouseEventArgs.GetMouseArgs(e).Handled = True
GridViewItem_Clicked = "GROUP"
Dim info = hi.Column.FieldName If e.Button = MouseButtons.Left Then
Dim info1 = hi.ToString ' wenn in eine Group Row Doppelt geklickt wurde..
Dim msg = "" If hi.InGroupRow And Not groupRowButtonClicked Then
ElseIf hi.InDataRow Then ' Ein/Ausklappen verhindern
GridViewItem_Clicked = "ROW" DXMouseEventArgs.GetMouseArgs(e).Handled = True
Else GridViewItem_Clicked = "GROUP"
GridViewItem_Clicked = Nothing ElseIf hi.InDataRow Then
GridViewItem_Clicked = "ROW"
Else
GridViewItem_Clicked = Nothing
End If
End If End If
End Sub End Sub
@ -1498,9 +1494,8 @@ Public Class frmMain
SaveGridLayout() SaveGridLayout()
End Sub End Sub
Private Sub GridView_Docs_GroupRowExpandCollapse(sender As Object, e As RowEventArgs) Handles GridView_Docs.GroupRowExpanded, GridView_Docs.GroupRowCollapsed Private Sub GridView_Docs_LostFocus(sender As Object, e As EventArgs) Handles GridView_Docs.LostFocus
'GridView_Docs.EndSelection() ' Save expanded GroupRows
SaveGridLayout() RefreshHelper.SaveViewInfo()
End Sub End Sub
End Class End Class