You have an excellent example of how to do CellFormatting on a Details ListView for a Bound list. My issue is trying to mimmic the same effect with an unbound list.
Dim productRowView As DataRowView = TryCast(cell.Row.DataBoundItem, DataRowView)If productRowView IsNot Nothing AndAlso CBool(productRowView.Row("Discontinued")) = True Then e.CellElement.BackColor = Color.Yellow e.CellElement.ForeColor = Color.Red e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid e.CellElement.Font = newFontElse e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local) e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local) e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local) e.CellElement.ResetValue(LightVisualElement.FontProperty, Telerik.WinControls.ValueResetFlags.Local)End If
I don't know how to find if a row is "Discontinued" when the data isn't bound to the list.
Right now my ListView is heavily lagged and I'm not sure if it's due to the fact that I'm not resetting the values or if it's due to the functions involved with formatting the cells.
4 Answers, 1 is accepted
You can acces a filed value by using the column name. Here is an example:
Private Sub RadListView1_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.ListViewCellFormattingEventArgs) Dim cell As DetailListViewDataCellElement = TryCast(e.CellElement, DetailListViewDataCellElement) If cell IsNot Nothing Then Dim value = cell.Row("Column1").ToString() If value IsNot Nothing AndAlso value = "Test1" Then e.CellElement.BackColor = Color.Yellow e.CellElement.ForeColor = Color.Red e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid Else e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local) e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local) e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local) End If End IfEnd SubI hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik
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.
The entire ListView takes a dump when I add the CellFormatting code below:
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 IfEnd Sub
A few key ingredients here.
GetFromRow: Just returns Trim(DataRowObject.Item(ColumnIndex))
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.
Anyway, am I doing something wrong in the CellFormatting?
I noticed that you have opened a ticket for this. We can continue to discuss this there.
Do not hesitate to contact us if you have other questions.
Dimitar
Progress Telerik
