I have a annoying problem with repainting my devexpress XtraGrid.
I use this code to draw Icons into a cell:
Private Sub CtlGridView_CustomDrawCell(sender As Object, e As RowCellCustomDrawEventArgs) Handles CtlGridView.CustomDrawCell
If e.Column.FieldName = NameOf(DataModel.Contract.Status) Then
Dim view As GridView = CType(sender, GridView)
Dim iconKeys As New List(Of String)
' Check Validation
Dim guidString As String = view.GetRowCellValue(e.RowHandle, NameOf(DataModel.Contract.GuidId)).ToString()
Dim guidId As Guid
If Guid.TryParse(guidString, guidId) Then
Dim validationResult As New DataModel.ValidationResult()
' Check if result is in cache
If Not _validationCache.TryGetValue(guidId, validationResult) Then
Task.Run(Sub()
Using taskContext As New DbContext()
Dim entry As DataModel.Contract= taskContext.Contracts.Find(guidId)
If entry IsNot Nothing Then
validationResult = entry.Validate(taskContext, exitOnFirstError:=True)
Else
validationResult = New DataModel.ValidationResult
End If
' Add result to cache
_validationCache.TryAdd(guidId, validationResult)
End Using
End Sub)
End If
If cellValue = "O" Then
iconKeys.Add("trackingchanges_showmarkup")
ElseIf cellValue = "T" Then
iconKeys.Add("trackingchanges_trackchanges")
ElseIf cellValue = "I" Then
iconKeys.Add("functionsinformation")
ElseIf cellValue = "G" Then
iconKeys.Add("trackingchanges_locktracking")
ElseIf cellValue = "W" Then
iconKeys.Add("trackingchanges_allmarkup")
ElseIf cellValue = "K" Then
iconKeys.Add("business_cash")
End If
If validationResult.Icon IsNot Nothing Then
iconKeys.Add(validationResult.Icon)
End If
If iconKeys.Count > 0 Then
Dim iconSize As New Size(32, 32)
IconHelper.DrawIcons(e, iconKeys, _imageCollection, iconSize)
End If
e.Handled = True
End If
End If
End Sub
As you can see, I am using a task to perform a validation, and with the validation result, I get back the icon name, which I then use to draw into the cell. This works without any issues, but there is a problem: the icon is displayed only after moving over the cell with my mouse or clicking some buttons on the form. It is related to the repaint of the form, but I don't know how to handle it.
Here is a link to a video which shows the effect: https://drive.google.com/file/d/1EAXSd2S4wczKdtq2E4KFR47eEAtQRY3L/view?usp=drive_link
Unfortunately the little bird can't help me either :-)
It seems to work ok, but some validation icons appearing first after moving the mouse over it.
I tried to invalidate the entire view/row/cell like this:
If Not _validationCache.TryGetValue(guidId, validationResult) Then
Task.Run(Sub()
Using taskContext As New DbContext()
Dim entry As DataModel.InstAuftrag = taskContext.InstAuftraege.Find(guidId)
If entry IsNot Nothing Then
validationResult = entry.Validate(taskContext, exitOnFirstError:=True)
Else
validationResult = New DataModel.ValidationResult
End If
' Add result to cache
_validationCache.TryAdd(guidId, validationResult)
End Using
End Sub)
view.invalidate
End If
This works only for the initial load, but when I scroll down my list, the GUI is locked for some time, which is really annoying.
Is there any better way to accomplish this task?
Thank you!
Adding
view.RefreshRow(e.RowHandle)
here:
Task.Run(Sub()
Using taskContext As New DbContext()
Dim entry As DataModel.Contract= taskContext.Contracts.Find(guidId)
If entry IsNot Nothing Then
validationResult = entry.Validate(taskContext, exitOnFirstError:=True)
Else
validationResult = New DataModel.ValidationResult
End If
' Add result to cache
_validationCache.TryAdd(guidId, validationResult)
view.RefreshRow(e.RowHandle)
End Using
End Sub)