My ListView is populated with data from a DataSet object. The ListView isn't bound to the dataset. I loop through the dataset and create the items for the ListView. Without cell formatting, the ListView is slightly laggy. It doesn't scroll as smoothly as I think it should. There's a small bit of hesitation that I can clearly see if I try to scroll quickly.
Private
Sub
lvEquip_CellFormatting(sender
As
Object
, e
As
ListViewCellFormattingEventArgs)
'Handles lvEquip.CellFormatting
Dim
cell
As
DetailListViewDataCellElement = TryCast(e.CellElement, DetailListViewDataCellElement)
If
cell IsNot
Nothing
Then
If
cell.Row(
"Col1"
).ToString() IsNot
Nothing
Then
Dim
DR
As
DataRow = cell.Row.Tag
Dim
C
As
Color
Select
Case
e.CellElement.Data.Name
Case
"Col4"
'Status
Select
Case
GetFromRow(DR, EquipmentCI.Status)
Case
"Resolved"
C = Color.Green
Case
"UnResolved"
C = Color.Red
Case
"Temporary Resolution"
C = Color.Orange
End
Select
e.CellElement.ForeColor = C
Case
"Col5"
'Pump Stand Status
Dim
ID
As
Integer
=
If
(IsNumeric(GetFromRow(DR, EquipmentCI.PSStatus)),
CInt
(GetFromRow(DR, EquipmentCI.PSStatus)), 0)
Select
Case
DirectCast
(ID, PSStatus)
Case
PSStatus.PS
C = Color.Red
Case
PSStatus.A
C = Color.Orange
Case
PSStatus.R
C = Color.Green
End
Select
e.CellElement.ForeColor = C
Case
"Col18"
'Last PM
Dim
LPM
As
String
= GetFromRow(DR, EquipmentCI.LastPM)
Dim
EH
As
String
= GetFromRow(DR, EquipmentCI.EngineHours)
If
LPM.Length < 1
Then
LPM = 0
If
EH.Length < 1
Then
EH = 0
Dim
Cnt
As
Integer
=
CInt
(EH) -
CInt
(LPM)
If
Cnt >= LastPM_High
Then
C = Color.Red
ElseIf
Cnt >= LastPM_Medium
Then
C = Color.Orange
Else
C = Color.Green
End
If
e.CellElement.ForeColor = C
Case
"Col21"
'Sec Last PM
Dim
LPM
As
String
= GetFromRow(DR, EquipmentCI.SecLastPM)
Dim
EH
As
String
= GetFromRow(DR, EquipmentCI.SecEngineHours)
If
LPM.Length < 1
Then
LPM = 0
If
EH.Length < 1
Then
EH = 0
Dim
Cnt
As
Integer
=
CInt
(EH) -
CInt
(LPM)
If
Cnt >= LastPM_High
Then
C = Color.Red
ElseIf
Cnt >= LastPM_Medium
Then
C = Color.Orange
Else
C = Color.Green
End
If
e.CellElement.ForeColor = C
Case
"Col23"
'Fed Insp
If
GetFromRow(DR, EquipmentCI.FedInsp).Length > 0
Then
Dim
DT
As
DateTime = FMDB(GetFromRow(DR, EquipmentCI.FedInsp),
False
)
Dim
Diff
As
Long
= DateDiff(DateInterval.Month, DT, DateTime.Now)
If
Diff >= 13
Then
C = Color.Red
ElseIf
Diff >= 6
Then
C = Color.Orange
Else
C = Color.Green
End
If
End
If
e.CellElement.ForeColor = C
Case
Else
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
End
Select
Else
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
End
If
End
If
End
Sub
A few key ingredients here.
FMDB: Short for FormatDateBack converts a MySQL formatted DateTime string back to a DateTime object. The boolean indicates whether I want to include the time.