This is a migrated thread and some comments may be shown as answers.
RadListView Unbound CellFormatting
4 Answers 25 Views
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 22 Jan 2019, 11:19 PM

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 = newFont
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)
    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

Sort by
0
Dimitar
Telerik team
answered on 23 Jan 2019, 01:06 PM
Hi Brandon,

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 If
End Sub

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Brandon
Top achievements
Rank 1
answered on 23 Jan 2019, 02:03 PM

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 If
End 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?

0
Brandon
Top achievements
Rank 1
answered on 23 Jan 2019, 03:18 PM
Update: I thought that maybe the ListView was more efficient when used in Bound mode so I converted the ListView over to use a Bound collection.  I now get an even more laggy experience without the CellFormatting.
0
Dimitar
Telerik team
answered on 24 Jan 2019, 11:21 AM
Hello Brandon,

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.
 
Regards,
Dimitar
Progress Telerik
Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Brandon
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Brandon
Top achievements
Rank 1
Share this question
or