Setting Border and Back Color of ListBoxItems

Thread is closed for posting
2 posts, 0 answers
  1. Versile
    Versile avatar
    20 posts
    Member since:
    May 2009

    Posted 28 Jun 2010 Link to this post


    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

  2. Boryana
    Boryana avatar
    330 posts

    Posted 30 Jun 2010 Link to this post

    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,
    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
Back to Top