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

How to Override RadListBox (Obsolete) Items Theme Properties

3 Answers 128 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.
Ghulam Haider
Top achievements
Rank 1
Ghulam Haider asked on 15 Oct 2010, 02:32 PM
Hi I am using Telerik Rad Q2 Controls for Winforms. I have following two questions and I have searched a lot but could not found. 1- How I can assign different ForeColors for list Box Items if ListBox have a theme. 2- How to Remove the bottom scroll bar so that if the contents are large then display on multiple lines Autoscroll property of listbox is false. but till bottom scroll bar automatically displays~26nbsp~3b Please response early. Thanks in advance Ghulam Haider

3 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 03:05 PM
Hello again,

1. Here is a test example on how to change the fore color of the items when creating them (bound and unbound)
using System;
using System.Drawing;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadListBox radListBox1;
 
    public Form1()
    {
        InitializeComponent();
 
        this.Controls.Add(radListBox1 = new RadListBox());
        radListBox1.Dock = DockStyle.Fill;
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        //LoadItemsUnbound();
        LoadItems();
    }
 
    private void LoadItemsUnbound()
    {
        for (int i = 0; i < 10; i++)
        {
            var item = new RadListBoxItem("Text TextText, Text " + i);
            item.DescriptionText = "This is a long description of the previous text";
            item.ForeColor = i % 2 == 0 ? Color.Red : Color.Blue;
            radListBox1.Items.Add(item);
        }
    }
 
    private void LoadItems()
    {
        radListBox1.ItemDataBound += new ItemDataBoundEventHandler(radListBox1_ItemDataBound);
        radListBox1.DataSource = new string[] { "Test item 1", "Test item 2", "Test item 3", "Test item 4", "Test item 5" };
    }
 
    void radListBox1_ItemDataBound(object sender, ItemDataBoundEventArgs e)
    {
        var listBoxItem = e.DataBoundItem as RadListBoxItem;
        if (listBoxItem != null)
        {
            listBoxItem.ForeColor = radListBox1.Items.Count % 2 == 0 ? Color.Red : Color.Blue;
        }
    }
}

2. There is no text wrap property for the listbox, for this you should switch to the newer RadListControl which offers this possibility.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Ghulam Haider
Top achievements
Rank 1
answered on 15 Oct 2010, 04:33 PM
Perfect solution. Thanks for your quick response. For second problem, I have just put a new line character "/n" in my string that has solved my problem. Again thanks.
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 04:37 PM
Hello again, yes, that does the trick but that is not something automated, but you can always use a Graphics.MeasureString(...) and if the width of that string is > than the width of the ListBox control insert the Environment.NewLine() into the string.

Glad to be able to help, if you have any more questions please just let me know, and if the question has been solved, please mark the question as answered, so that others can find the answers to their questions faster.

Best Regards,
Emanuel Varga
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Ghulam Haider
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Ghulam Haider
Top achievements
Rank 1
Share this question
or