I have a annoying problem with repainting my devexpress XtraGrid.
I use this code to draw Icons into a cell:
' 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.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)
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 using a task to do a validation and with that 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 the problem, that 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.
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 and it’s really annoying.
Is there any better way to accomplish this task?
Thank you!