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

Excel-Like Filtering, Changing color of FilterList items in the Listbox

2 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 23 May 2017, 04:09 PM

I'm trying to change the color of certain items in my listbox in the filtering item to be red if the item contains parenthesis.  I am doing a simple databind to populate my listbox in the FilterCheckListItemsRequested event from a datatable which I populate myself.

e.ListBox.DataSource = dtDataForFiltering; //DataTable
e.ListBox.DataKeyField = datafield;
e.ListBox.DataTextField = datafieldtext;
e.ListBox.DataValueField = datafield;
e.ListBox.DataBind();

 

This is working fine.  Now I am trying to find out how to alter the items in the listbox after it has been filled with data.  I tried looping through it's items and setting the color, but I am not sure if I am doing this correctly or if this is the correct place to do it.  Any help would be appreciated.

Please see image attached.  I am trying to alter items in my filter to be red if in parenthesis, just like the grid in the background.

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 May 2017, 10:28 AM
Hello Chris,

You can achieve this requirement using the following approach:
e.ListBox.DataBind();
 
foreach (RadListBoxItem item in e.ListBox.Items)
{
    if (item.Text.Contains("3"))
    {
        item.BackColor = System.Drawing.Color.Lime;
    }
}

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Chris
Top achievements
Rank 1
answered on 26 May 2017, 11:09 AM

This worked for me.  I guess I was doing it wrong the first time.

 

Thanks

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Chris
Top achievements
Rank 1
Share this question
or