Change ListViewDataItem BackColor

3 posts, 0 answers
  1. Simon
    Simon avatar
    11 posts
    Member since:
    Aug 2011

    Posted 11 Nov 2014 Link to this post

    I want to change the
    backcolor of a listViewDataItem, then later on, change it back to the standard
    color (ie white if it's not selected or the standard selection color of it's

    I'm using this code to change the backcolor:

    previewedListItem.BackColor = Color.Gold
    previewedListItem.BackColor2 = Color.Gold
    previewedListItem.BackColor3 = Color.Gold
    previewedListItem.BackColor4 = Color.Gold

    and this code to change it back:

    previewedListItem.BackColor = Color.FromArgb(0, 0, 0, 0)
    previewedListItem.BackColor2 = Color.FromArgb(0, 0, 0, 0)
    previewedListItem.BackColor3 = Color.FromArgb(0, 0, 0, 0)
    previewedListItem.BackColor4 = Color.FromArgb(0, 0, 0, 0)

    The problem is that once I've changed it back, if the user selects that item,
    it stays white instead of showing the selection color. How can I change the
    color back in a way that will still show the selection color if the item is
  2. Simon
    Simon avatar
    11 posts
    Member since:
    Aug 2011

    Posted 11 Nov 2014 in reply to Simon Link to this post

    Also, I've seen the article about using the VisualItemFormatting event to change the backcolor. Using this approach, I'm not sure how to work out which item I should be changing the backcolor of. I would like to check the value of one of the items in the listviewdataitem.databounditem and change the backcolor depending on the value. How do I get to the databound item in the VisaItemFormatting event?
  3. DevCraft R3 2016 release webinar banner
  4. Stefan
    Stefan avatar
    2891 posts

    Posted 12 Nov 2014 Link to this post

    Hi Simon,

    Thank you for writing.

    To reset a setting introduced in a formatting event, you need to use the ResetValue method and reset the locally introduced settings:
    e.VisualItem.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);

    And here is how to access the data bound value:

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top