Footer and Header in DropDownList

6 posts, 0 answers
  1. Oren
    Oren avatar
    6 posts
    Member since:
    Dec 2010

    Posted 28 Apr 2011 Link to this post

    Hello,

    Is it possible to create a header and footer for dropdownlist control,
    and to insert controls to it?
    exactly like in the asp.net ajax combobox control.

    Thanks,
    Oren
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 29 Apr 2011 Link to this post

    Hello Oren,

    Just create a custom control, dock other controls to the top + bottom, and dock the dropdownlist to fill.

    Something like this:
    using System.ComponentModel;
    using System.Windows.Forms;
    using Telerik.WinControls;
    using Telerik.WinControls.UI;
     
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var customDropDownList = new CustomDropDownList();
            var label = new RadLabel();
            label.Text = "Header";
            customDropDownList.HeaderControl = label;
            label = new RadLabel();
            label.Text = "Footer";
            customDropDownList.FooterControl = label;
            this.Controls.Add(customDropDownList);
            customDropDownList.Dock = DockStyle.Fill;
        }
    }
     
    [ToolboxItem(true)]
    public class CustomDropDownList : RadControl
    {
        private Control headerControl;
     
        private Control footerControl;
     
        private RadDropDownList customDropDownList;
     
        public CustomDropDownList()
        {
            customDropDownList = new RadDropDownList();
            this.Controls.Add(customDropDownList);
            customDropDownList.Dock = DockStyle.Fill;
        }
     
        public Control HeaderControl
        {
            get { return headerControl; }
     
            set
            {
                if (headerControl != value)
                {
                    CleanupControl(headerControl);
                    headerControl = value;
                    OnControlChanged(headerControl, true);
                }
            }
        }
     
        public Control FooterControl
        {
            get { return footerControl; }
            set
            {
                if (footerControl != value)
                {
                    CleanupControl(footerControl);
                    footerControl = value;
                    OnControlChanged(footerControl, false);
                }
            }
        }
     
        private void OnControlChanged(Control control, bool header)
        {
            this.Controls.Add(control);
            control.Dock = header ? DockStyle.Top : DockStyle.Bottom;
            this.Controls.SetChildIndex(control, header ? 1 : 2);
        }
     
        private void CleanupControl(Control control)
        {
            if (control == null)
            {
                return;
            }
     
            this.Controls.Remove(control);
            control.Dispose();
            control = null;
        }
    }

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

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 04 May 2011 Link to this post

    Hi all,

    Emanuel, thank you for your suggestion.

    Oren, please check the help article suggested by Emanuel. It describes how to create a custom control.
    Please do not hesitate to contact us if you have further questions.

    Greetings,
    Peter
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  5. Oren
    Oren avatar
    6 posts
    Member since:
    Dec 2010

    Posted 16 May 2011 Link to this post

    Hi,

    I just copied and run the suggested code and i didn't get the desire behaviour.(see image attached),
    My request is to build a custom control from RadDropDownList (to inherite RadDropDownList ),
    and to add header/footer with buttons (asp buttons) that could be functionality.

    The main idea is to add radtreeview inside the dropdown exactly like i did in asp.net ajax.

    Please see the attached images and help me to mimic the custom server control i did in asp.net ajax.

    I use Telerik Controls Q1 2011

    Thank's
    Oren
  6. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 16 May 2011 Link to this post

    Hello again Oren,

    This is a totally different thing, and i would suggest again a different approach.
    I would just suggest using a splitButton for this, for the look and feel with that down arrow, and then creating your own custom form which you will be showing when the user clicks on that button, simulating a dropdown but doing something totally different, and then you can create that form however you would like.

    I hope you understood what i'm trying to say here.

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

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  7. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 19 May 2011 Link to this post

    Hi all,

    Emanuel, thank you very much for your suggestion.

    Oren, please refer to the attached sample project. I hope it illustrates the desired behavior. In case you have further queries, do not hesitate to contact us.

    Regards,
    Boryana
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Back to Top
UI for WinForms is Visual Studio 2017 Ready