This is a migrated thread and some comments may be shown as answers.

How to highlight a row in ListView based on its value

4 Answers 115 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Bala
Top achievements
Rank 1
Bala asked on 05 Jun 2013, 02:00 PM
Unbound radlistView, I want to highlight certain rows if its text is a certain pattern
How to achieve that?

Thanks

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 10 Jun 2013, 06:09 AM
Hello Bala,

Thank you for writing.

To do that you would have to use the formatting events of the control:
//Details view
void radListView1_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    if (e.CellElement.Text.Contains("4"))
    {
        e.CellElement.DrawFill = true;
        e.CellElement.GradientStyle = GradientStyles.Solid;
        e.CellElement.BackColor = Color.Red;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
    }
}
 
//Other views
void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
{
    if (e.VisualItem.Text.Contains("4"))
    {
        e.VisualItem.DrawFill = true;
        e.VisualItem.GradientStyle = GradientStyles.Solid;
        e.VisualItem.BackColor = Color.Red;
    }
    else
    {
        e.VisualItem.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.VisualItem.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.VisualItem.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
    }
}

More information and examples are available here: http://www.telerik.com/help/winforms/listview-custom-items.html.

I hope this helps.
 

Regards,
Stefan
Telerik
RadChart for WinForms is obsolete. Now what?
0
Bala
Top achievements
Rank 1
answered on 27 Jun 2013, 07:40 PM
Thanks a lot! Works!
0
Vlad
Top achievements
Rank 1
answered on 03 May 2015, 05:43 AM
Private Sub lstUsers_VisualItemFormatting(sender As Object, e As ListViewVisualItemEventArgs) Handles lstUsers.VisualItemFormatting
        If (e.VisualItem.Text.Contains("3OFFLINE")) Then
            e.VisualItem.DrawFill = True
            e.VisualItem.GradientStyle = GradientStyles.Solid
            e.VisualItem.BackColor = Color.Red
        Else
            e.VisualItem.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
            e.VisualItem.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
            e.VisualItem.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
        End If
    End Sub
This does not work
0
Vlad
Top achievements
Rank 1
answered on 03 May 2015, 06:53 AM

 e.VisualItem.Data("Column 1") = "3OFFLINE" it works.

Tags
ListView
Asked by
Bala
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Bala
Top achievements
Rank 1
Vlad
Top achievements
Rank 1
Share this question
or