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

Get backcolor and forecolor of SubItem

1 Answer 29 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Lauren
Top achievements
Rank 1
Lauren asked on 18 Jun 2014, 09:16 PM
I'm setting the backcolor and forecolor of SubItems in the radListView1_CellFormatting event.  Later, I'm exporting my List View to Excel, and I need to access the backcolor and forecolor of each SubItem/cell.  Is this possible?  I see the property for Item backcolor, but I can't get at the SubItem backcolor.

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 23 Jun 2014, 12:14 PM
Hello Lauren,

Thank you for writing.

You can create a caching mechanism to store the colors. This will require creating a unique key to retrieve the colors from a dictionary:
Dictionary<object, Color[]> cache = new Dictionary<object, Color[]>();
void listView_CellFormatting(object sender, ListViewCellFormattingEventArgs e)
{
    RadListViewElement element = sender as RadListViewElement;
    if (e.CellElement is DetailListViewDataCellElement)
    {
        DetailListViewDataCellElement cell = e.CellElement as DetailListViewDataCellElement;
        ListViewDetailColumn column = cell.Data;
        object keyItem = cell.Row[element.Columns.IndexOf(column)] + column.FieldName;
        if (!cache.ContainsKey(keyItem))
        {
            cache[keyItem] = new Color[2];
        }
 
        e.CellElement.BackColor = cache[keyItem][0] = Color.Red;
        e.CellElement.ForeColor = cache[keyItem][1] = Color.Blue;
    }
 
}

When you want to retrieve the colors you can do it by accessing the Columns and the Items collection of RadListView, as each Item in the Items collection is the Row of a cell.

Do not hesitate to write back, should you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
ListView
Asked by
Lauren
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or