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

RadListbox function

3 Answers 130 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.
Steven
Top achievements
Rank 1
Steven asked on 10 Dec 2006, 09:03 PM
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

3 Answers, 1 is accepted

Sort by
0
Chris
Telerik team
answered on 11 Dec 2006, 02:03 PM
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
0
Steven
Top achievements
Rank 1
answered on 12 Dec 2006, 07:46 PM
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

0
Chris
Telerik team
answered on 13 Dec 2006, 08:52 AM
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
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Steven
Top achievements
Rank 1
Answers by
Chris
Telerik team
Steven
Top achievements
Rank 1
Share this question
or