How to highlight a row in ListView based on its value

5 posts, 1 answers
  1. Bala
    Bala avatar
    10 posts
    Member since:
    Nov 2011

    Posted 05 Jun 2013 Link to this post

    Unbound radlistView, I want to highlight certain rows if its text is a certain pattern
    How to achieve that?

    Thanks
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Jun 2013 Link to this post

    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?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bala
    Bala avatar
    10 posts
    Member since:
    Nov 2011

    Posted 27 Jun 2013 Link to this post

    Thanks a lot! Works!
  5. Vlad
    Vlad avatar
    12 posts
    Member since:
    Jun 2010

    Posted 03 May 2015 in reply to Stefan Link to this post

    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
  6. Vlad
    Vlad avatar
    12 posts
    Member since:
    Jun 2010

    Posted 03 May 2015 Link to this post

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

Back to Top
UI for WinForms is Visual Studio 2017 Ready