Common/DocumentResultList: Fix reloading gridcontrol by using delegate in RefreshResults call
This commit is contained in:
@@ -77,7 +77,8 @@ Public Class frmDocumentResultList
|
||||
Public Event NeedsRefresh As EventHandler(Of Integer) Implements IResultForm.NeedsRefresh
|
||||
Public Event ResultsRefreshed As EventHandler(Of List(Of DocumentResultList.DocumentResult))
|
||||
|
||||
Public Delegate Sub SetDatasourceCallback(pDatatable As DataTable)
|
||||
Private Delegate Sub DatasourceDelegate(View As GridView, Datasource As Object)
|
||||
Private Delegate Function RefreshResultsDelegate(Results As IEnumerable(Of BaseResult)) As Boolean
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pEnvironment As Environment, pParams As DocumentResultList.Params)
|
||||
' Dieser Aufruf ist für den Designer erforderlich.
|
||||
@@ -325,7 +326,7 @@ Public Class frmDocumentResultList
|
||||
If IsNothing(oObjectId) Then
|
||||
MsgBox($"Beim Speichern der Datei '{oDisplayName}' Fehler ist ein Fehler aufgetreten!", MsgBoxStyle.Critical, Text)
|
||||
Else
|
||||
MsgBox($"Die Datei '{oDisplayName}' wurde erfolgreich gespeichert!", MsgBoxStyle.Information, Text)
|
||||
'MsgBox($"Die Datei '{oDisplayName}' wurde erfolgreich gespeichert!", MsgBoxStyle.Information, Text)
|
||||
RaiseEvent NeedsRefresh(Me, Params.ProfileGuid)
|
||||
End If
|
||||
End Function
|
||||
@@ -372,23 +373,32 @@ Public Class frmDocumentResultList
|
||||
|
||||
|
||||
Public Function RefreshResults(pResults As IEnumerable(Of BaseResult)) As Boolean Implements IResultForm.RefreshResults
|
||||
_IsLoading = True
|
||||
Try
|
||||
UpdateTotalResults()
|
||||
UpdateGridData()
|
||||
' This is needed to update the grid from another form like frmMatch
|
||||
' Another form means another thread, so we need a delegate here
|
||||
If InvokeRequired Then
|
||||
Dim oDelegate As New RefreshResultsDelegate(AddressOf RefreshResults)
|
||||
Return GridControl1.Invoke(oDelegate, pResults)
|
||||
Else
|
||||
_IsLoading = True
|
||||
Try
|
||||
_ResultLists = pResults
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
UpdateTotalResults()
|
||||
UpdateGridData()
|
||||
|
||||
MessageBox.Show("Error while loading results:" & vbNewLine & vbNewLine & ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||||
Return False
|
||||
Finally
|
||||
_IsLoading = False
|
||||
End Try
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
|
||||
MessageBox.Show("Error while refreshing results:" & vbNewLine & vbNewLine & ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||||
Return False
|
||||
Finally
|
||||
_IsLoading = False
|
||||
End Try
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Sub LoadGridData(Result As DocumentResultList.DocumentResult)
|
||||
Private Sub LoadGridData(View As GridView, Result As DocumentResultList.DocumentResult)
|
||||
If Result.Datatable.Columns.Contains(COLUMN_DOCID) = False Then
|
||||
Throw New ApplicationException($"Datatable is missing DocId Column [{COLUMN_DOCID}] for search {Result.Title}!")
|
||||
End If
|
||||
@@ -397,22 +407,26 @@ Public Class frmDocumentResultList
|
||||
Throw New ApplicationException($"Datatable is missing Filepath Column [{COLUMN_FILEPATH}] for search {Result.Title}!")
|
||||
End If
|
||||
|
||||
' This is needed to update the grid from another form like frmMatch
|
||||
' Another form means another thread, so we need a delegate here
|
||||
If GridControl1.InvokeRequired Then
|
||||
Dim oCallback As New SetDatasourceCallback(AddressOf SetGridDataSource)
|
||||
Invoke(oCallback, Result.Datatable)
|
||||
|
||||
Else
|
||||
SetGridDataSource(Result.Datatable)
|
||||
End If
|
||||
SetGridDataSource(View, Result.Datatable)
|
||||
End Sub
|
||||
|
||||
Private Sub SetGridDataSource(pTable As DataTable)
|
||||
GridControl1.DataSource = Nothing
|
||||
GridControl1.DataSource = pTable
|
||||
|
||||
Private Sub SetGridDataSource(pView As GridView, pTable As DataTable)
|
||||
Dim oSavedRowHandle As Integer = pView.FocusedRowHandle
|
||||
pView.BeginDataUpdate()
|
||||
|
||||
Try
|
||||
pView.FocusedRowHandle = GridControl.AutoFilterRowHandle
|
||||
pView.GridControl.DataSource = Nothing
|
||||
pView.GridControl.DataSource = pTable
|
||||
pView.FocusedRowHandle = oSavedRowHandle
|
||||
Finally
|
||||
pView.EndDataUpdate()
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Private Sub UpdateGridData()
|
||||
' Load Grids
|
||||
For oIndex = 0 To _ResultLists.Count - 1
|
||||
@@ -420,7 +434,7 @@ Public Class frmDocumentResultList
|
||||
Case 0
|
||||
Dim oResult As DocumentResultList.DocumentResult = _ResultLists.Item(0)
|
||||
|
||||
LoadGridData(oResult)
|
||||
LoadGridData(GridView1, oResult)
|
||||
CreateDocumentGrid(GridView1, oResult)
|
||||
RestoreLayout(GridView1)
|
||||
UpdateGridHeader(_ResultLists, oIndex, oResult.Datatable.Rows.Count)
|
||||
@@ -428,7 +442,7 @@ Public Class frmDocumentResultList
|
||||
Case 1
|
||||
Dim oResult As DocumentResultList.DocumentResult = _ResultLists.Item(1)
|
||||
|
||||
LoadGridData(oResult)
|
||||
LoadGridData(GridView2, oResult)
|
||||
CreateDocumentGrid(GridView2, oResult)
|
||||
RestoreLayout(GridView2)
|
||||
UpdateGridHeader(_ResultLists, oIndex, oResult.Datatable.Rows.Count)
|
||||
@@ -436,7 +450,7 @@ Public Class frmDocumentResultList
|
||||
Case 2
|
||||
Dim oResult As DocumentResultList.DocumentResult = _ResultLists.Item(2)
|
||||
|
||||
LoadGridData(oResult)
|
||||
LoadGridData(GridView3, oResult)
|
||||
CreateDocumentGrid(GridView3, oResult)
|
||||
RestoreLayout(GridView3)
|
||||
UpdateGridHeader(_ResultLists, oIndex, oResult.Datatable.Rows.Count)
|
||||
|
||||
Reference in New Issue
Block a user