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

Change ListViewDataItem BackColor

2 Answers 151 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 11 Nov 2014, 10:44 PM
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
selected).

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
selected?

2 Answers, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 11 Nov 2014, 10:56 PM
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?
0
Stefan
Telerik team
answered on 12 Nov 2014, 06:54 AM
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:
e.VisualItem.Data.DataBoundItem

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

Regards,
Stefan
Telerik
 

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.

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