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

Setting Border and Back Color of ListBoxItems

1 Answer 388 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Versile
Top achievements
Rank 1
Versile asked on 28 Jun 2010, 10:58 PM
Hi,

I'm trying to create listbox items programatically and have been so far completely unable to set the back color of the listbox items or to turn the borders on for all listboxitems. Please help.

        // Method to set default ListItem properties 
        private RadListBoxItem newListItem(string displayText, int ID, GMapMarker marker) 
        { 
            RadListBoxItem item = new RadListBoxItem(); 
            item.ImageAlignment = ContentAlignment.MiddleLeft; 
            item.TextImageRelation = TextImageRelation.ImageBeforeText; 
            if (marker is JobMarker) 
            { 
                item.Image = (Image)Properties.Resources.ResourceManager.GetObject(((JobMarker)marker).IconFileName); 
                if (!((JobMarker)marker).IsGeoCoded) 
                    item.BackColor = Color.LightPink; 
            } 
            else if (marker is EmployeeMarker) 
            { 
                item.Image = (Image)Properties.Resources.ResourceManager.GetObject(((EmployeeMarker)marker).IconFileName); 
                if (!((EmployeeMarker)marker).isGeoCoded) 
                { 
                    item.BackColor = Color.LightPink; 
                } 
            } 
            item.Text = displayText; 
            item.Tag = ID; 
            return item; 
        } 

This is the code I am using to create the listboxitem

1 Answer, 1 is accepted

Sort by
0
Boryana
Telerik team
answered on 30 Jun 2010, 01:15 PM
Hello Versile,

Thank you for contacting us.

The RadListBoxItem is built from a FillPrimitive and a BorderPrimitive. These control the appearance of the item. So instead of setting the RadListBoxItem itself, you will need to set specific properties of the appropriate primitive. Here is a sample snippet that illustrates this approach:

FillPrimitive fp = ((FillPrimitive)radListBoxItem1.Children[0]);
fp.BackColor = Color.Pink;
fp.BackColor2 = Color.Orange;
fp.BackColor3 = Color.Yellow;
fp.BackColor4 = Color.Red;
fp.NumberOfColors = 4;
fp.GradientStyle = Telerik.WinControls.GradientStyles.Linear;
  
BorderPrimitive bp = (BorderPrimitive)radListBoxItem2.Children[1];
bp.ForeColor = Color.Pink;
bp.ForeColor2 = Color.Orange;
bp.ForeColor3 = Color.Yellow;
bp.ForeColor4 = Color.Red;
bp.BoxStyle = Telerik.WinControls.BorderBoxStyle.SingleBorder;
bp.GradientStyle = Telerik.WinControls.GradientStyles.Linear;

I hope this is helpful. Let me know if you have further questions.

Kind regards,
Boryana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Versile
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Share this question
or