RadListbox function

4 posts, 0 answers
  1. Steven
    Steven avatar
    4 posts
    Member since:
    Dec 2006

    Posted 10 Dec 2006 Link to this post

    Hi,

    i am searching for an element whitch i can place in RadListbox that can highlight textpeases. My favorit was changing color in the text like:
    abcdefghi

    Can the RadListbox handle this?

    Thanks for answers

    Steve
  2. Chris
    Admin
    Chris avatar
    221 posts

    Posted 11 Dec 2006 Link to this post

    Hi Stefan,
    Currently this is not possible "out of the box" even though you can still achieve the same effect by extending the ListBoxItem class and then add two more TextPrimitives in the CreateChildElements method. Then you can customize separately each text primitive. You can change separately each text size, font, color, etc.
    I hope this information helps.

    Sincerely yours,
    Chris
    the telerik team
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Steven
    Steven avatar
    4 posts
    Member since:
    Dec 2006

    Posted 12 Dec 2006 Link to this post

    Thanks for the information,

    i have try it. Now i have 3 text pieces in various colors. But the pieces was painted one on top of the other.

    Protected Overrides Sub CreateChildElements()
                MyBase.CreateChildElements()
                Dim new_text As New Telerik.WinControls.Primitives.TextPrimitive()
                new_text.Text = "Test"
                new_text.ForeColor = Color.Red
                Me.Children.Add(new_text)
    End Sub

    Can you tell me whats going wrong?

    Thanks,

    Steve

  5. Chris
    Admin
    Chris avatar
    221 posts

    Posted 13 Dec 2006 Link to this post

    Hi Stefan,
    I'm sorry if I have misled you with my previous answer.
    Yes, you can achieve this behavior but you should use some layout to arrange the new text primitives. By default each element uses a Canvas layout to position its elements and when you insert new elements in its structure they'll be positioned absolutely in the element's space.
    I have created a sample class which demonstrates this approach:

    Public Class MyListBoxItem
        
    Inherits RadListBoxItem

        Protected Overrides Sub CreateChildElements()
            
    MyBase.CreateChildElements()
            
    Dim layoutPanel As ImageAndTextLayoutPanel = CType(MyBase.Children(2), ImageAndTextLayoutPanel)    
            Dim stripPanel As StripLayoutPanel = CType(layoutPanel.Children(1), StripLayoutPanel)
            
    Dim itemText As TextPrimitive = CType(stripPanel.Children(0), TextPrimitive)
            
            Dim newStripPanel As StripLayoutPanel = New StripLayoutPanel()
            newStripPanel.Orientation = Orientation.Horizontal

            Dim redText As TextPrimitive = New TextPrimitive()
            redText.ForeColor = Color.Red
            redText.Text = " Red "

            Dim blueText As TextPrimitive = New TextPrimitive()
            blueText.ForeColor = Color.Blue
            blueText.Text = " Blue "

            stripPanel.Children.Remove(itemText)
            newStripPanel.Children.AddRange(
    New RadElement() { itemText, redText, blueText })
            stripPanel.Children.Insert(0, newStripPanel)
        
    End Sub

    End
    Class

    Here's a screenshot of a listbox which takes advantage of this new listbox item (I have set empty string for the second item's description text):

    You can easily enhance this class and expose the new primitives' Text properties as properties of the MyListBoxItem class.
    Please, let me know if this works fine for you.

    Best wishes,
    Chris
    the telerik team
Back to Top