How to Override RadListBox (Obsolete) Items Theme Properties

4 posts, 2 answers
  1. Ghulam Haider
    Ghulam  Haider avatar
    6 posts
    Member since:
    Feb 2010

    Posted 15 Oct 2010 Link to this post

    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
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 15 Oct 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ghulam Haider
    Ghulam  Haider avatar
    6 posts
    Member since:
    Feb 2010

    Posted 15 Oct 2010 Link to this post

    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.
  5. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 15 Oct 2010 Link to this post

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