Adding RadButtonElement to RadListBoxItem

3 posts, 0 answers
  1. Pierre Alain
    Pierre Alain avatar
    20 posts
    Member since:
    Jun 2008

    Posted 01 Jan 2010 Link to this post


    I'm adding a RadButtonElement to a RadListBoxItem and would like it to be right aligned, but can't seem to do it.

    Here is my code. The button is there, but stays on the left side.


    privatevoid lbConnections_ItemDataBound(object sender, Telerik.WinControls.UI.ItemDataBoundEventArgs e)   
        RadListBoxItem listBoxItem = (RadListBoxItem)e.DataBoundItem;  
        // Add button   
        RadButtonElement btn = new RadButtonElement();   
        btn.Alignment = ContentAlignment.MiddleRight;   
        btn.StretchHorizontally = false;   
        btn.StretchVertically = false;   
        btn.AutoSize = false;   
        btn.Size = new Size(15, 15);;   
        btn.Click += new EventHandler(btn_Click);   






  2. Nikolay
    Nikolay avatar
    1802 posts

    Posted 04 Jan 2010 Link to this post

    Hello pacarrier,

    The RadButtonElement is not aligned, because RadListBoxItem is just a holder of the elements, but it does not act as a layout panel.

    You can align the buttons to the right of the text by inserting the buttons in the StackLayoutPanel that holds the text. In this case the code snippet that you should use is:
    void radListBox1_ItemDataBound(object sender, Telerik.WinControls.UI.ItemDataBoundEventArgs e)
        RadListBoxItem listBoxItem = (RadListBoxItem)e.DataBoundItem;
        // Add button    
        RadButtonElement btn = new RadButtonElement();
        btn.AutoSize = false;
        btn.Size = new Size(15, 15);
        StackLayoutPanel stackPanel = (StackLayoutPanel)listBoxItem.Children[2].Children[1];
        stackPanel.Orientation = Orientation.Horizontal;
        stackPanel.Children[2].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;            

    Please note that the buttons will be aligned to the right depending on the length of the text. So if the strings have different sizes, the buttons will not be positioned in one 'column'.

    If you want to have the buttons in one column, this should be done with the help of the Margin property. I am attaching a sample project which demonstrates the approach.

    Another option for you is to use our RadGridView as RadListBox. The column that you need in this case for the buttons is GridViewCommandColumn.

    I hope this helps. If you have additional questions, feel free to contact me.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft R3 2016 release webinar banner
  4. Pierre Alain
    Pierre Alain avatar
    20 posts
    Member since:
    Jun 2008

    Posted 04 Jan 2010 Link to this post

    I finally used margin to solve my problem and handled the Resize event.

Back to Top