RadTreeView in RadDropDownList

8 posts, 0 answers
  1. Carsten
    Carsten avatar
    2 posts
    Member since:
    Dec 2013

    Posted 09 Dec 2013 Link to this post

    Hi,

    We have a RadTreeView in our RadDropDownList based on the sample found here:
    http://www.telerik.com/community/forums/winforms/combobox-and-listbox/treeview-in-dropdown.aspx

    But we seem to have some issues with it:

    If the 'Arrow Button' is clicked while the popup is open, then the 'arrow button' gets stuck as if it's still pressed but the popup itself is not showing. Once in this mode, any further clicks on the arrow button will display the popup and immediately close it again.
    This behavior is also reproducible in the sample attached in the forum post.

    I hope anyone has a way of getting around this.

    Thank you in advance.

    Carsten.
  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 12 Dec 2013 Link to this post

    Hello Carsten,

    Thank you for contacting Telerik Support.

    In order to apply the provided solution to RadDropDownList and the embedded RadTreeView in its pop up, you may use the following approach:
    RadHostItem h;
    RadTreeView radTreeView1;
     
    public Form1()
    {
        InitializeComponent();
     
        this.radTreeView1 = new RadTreeView();
        for (int i = 0; i < 50; i++)
        {
            RadTreeNode node = new RadTreeNode();
            node.Text = "Node" + i.ToString();
            this.radTreeView1.Nodes.Add(node);
        }
     
        this.radTreeView1.Dock = DockStyle.Fill;
        h = new RadHostItem(this.radTreeView1);
        this.radDropDownList1.DropDownMinSize = new Size(this.radDropDownList1.Width, 60);
        this.radTreeView1.SelectedNodeChanged += radTreeView1_SelectedNodeChanged;
     
        if (this.radDropDownList1.DropDownListElement.ListElement.Parent != null)
        {
            this.radDropDownList1.DropDownListElement.ListElement.Children.Insert(0, h);  
        }
    }
     
    private void radTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
    {
        this.radDropDownList1.DropDownListElement.ClosePopup();
        this.radDropDownList1.Text = this.radTreeView1.SelectedNodes[0].Text;
    }

    Please note that the referred solution in the forum thread is not a generic solution and it may not work correctly in all scenarios. Feel free to modify the approach according to your needs.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Carsten
    Carsten avatar
    2 posts
    Member since:
    Dec 2013

    Posted 12 Dec 2013 Link to this post

    Hi Desislava,

    That's awesome, it seems to work, thank you so much!
  5. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 16 Dec 2013 Link to this post

    Hello Carsten,

    I am glad that the issue you were facing is now resolved. Please do not hesitate to contact us if you have any additional questions.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Peter
    Peter avatar
    16 posts
    Member since:
    Apr 2012

    Posted 03 Jun 2014 Link to this post

    Hi All, 

    I was able to integrate a RadTreeView into the RadDropDownList with the approach suggested by Desislava. 

    Can you give me an example how to enable scrolling by mousewheel and arrow keys? 

    Thank you very much in advance,

    Peter 
  7. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 06 Jun 2014 Link to this post

    Hello Peter,

    Thank you for writing.

    You can achieve scrolling on mouse wheel for the RadTreeView hosted in the DropDownPopupForm following the approach below:
    RadHostItem h;
    RadTreeView radTreeView1;
    MethodInfo mi;
     
    public Form1()
    {
        InitializeComponent();
        this.radTreeView1 = new RadTreeView();
        for (int i = 0; i < 50; i++)
        {
            RadTreeNode node = new RadTreeNode();
            node.Text = "Node" + i.ToString();
            this.radTreeView1.Nodes.Add(node);
        }
        mi = radTreeView1.TreeViewElement.GetType().GetMethod("ProcessMouseWheel",
            BindingFlags.NonPublic | BindingFlags.Instance);
     
        this.radTreeView1.Dock = DockStyle.Fill;
        h = new RadHostItem(this.radTreeView1);
        this.radDropDownList1.DropDownMinSize = new Size(this.radDropDownList1.Width, 60);
        this.radTreeView1.SelectedNodeChanged += radTreeView1_SelectedNodeChanged;
     
        if (this.radDropDownList1.DropDownListElement.ListElement.Parent != null)
        {
            this.radDropDownList1.DropDownListElement.ListElement.Children.Insert(0, h); 
        }
     
        this.radDropDownList1.PopupOpened += radDropDownList1_PopupOpened;
    }
     
    private void radDropDownList1_PopupOpened(object sender, EventArgs e)
    {
        RadDropDownListElement ddle = sender as RadDropDownListElement;
        ddle.Popup.MouseWheel -= ddle_MouseWheel;
        ddle.Popup.MouseWheel += ddle_MouseWheel;
    }
     
    private void ddle_MouseWheel(object sender, MouseEventArgs e)
    {
        DropDownPopupForm popup = sender as DropDownPopupForm;
        RadTreeView tree = popup.Controls[0] as RadTreeView;
        if (tree != null && mi != null)
        {
            mi.Invoke(tree.TreeViewElement, new object[] { e });
        }
    }
     
    private void radTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
    {
        this.radDropDownList1.DropDownListElement.ClosePopup();
        this.radDropDownList1.Text = this.radTreeView1.SelectedNodes[0].Text;
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  8. Mudasser
    Mudasser avatar
    1 posts
    Member since:
    Oct 2015

    Posted 19 Oct 2015 in reply to Dess Link to this post

    Hi,

    We need to search through the RadTreeView nodes using the RadDropDownList control with DropdownStyle = DropDown.

    Is there anyway that as we write any text in the text area of DropDownList and it automatically show the relevant tree nodes in the popup?

     Thanks

    Mudasser Hameed

  9. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 21 Oct 2015 Link to this post

    Hello Mudasser,

    Thank you for writing.
     
    You can subscribe to the DropDownListElement.TextBox.TextChanged event and filter the tree view by setting the RadTreeView.Filter property:
    RadHostItem h;
    RadTreeView radTreeView1;
    MethodInfo mi;
     
    public Form1()
    {
        InitializeComponent();
        this.radTreeView1 = new RadTreeView();
        for (int i = 0; i < 50; i++)
        {
            RadTreeNode node = new RadTreeNode();
            node.Text = "Node" + i.ToString();
            this.radTreeView1.Nodes.Add(node);
        }
        mi = radTreeView1.TreeViewElement.GetType().GetMethod("ProcessMouseWheel",
            BindingFlags.NonPublic | BindingFlags.Instance);
     
        this.radTreeView1.Dock = DockStyle.Fill;
        h = new RadHostItem(this.radTreeView1);
        this.radDropDownList1.DropDownMinSize = new Size(this.radDropDownList1.Width, 60);
        this.radTreeView1.SelectedNodeChanged += radTreeView1_SelectedNodeChanged;
     
        if (this.radDropDownList1.DropDownListElement.ListElement.Parent != null)
        {
            this.radDropDownList1.DropDownListElement.ListElement.Children.Insert(0, h);  
        }
     
        this.radDropDownList1.PopupOpened += radDropDownList1_PopupOpened;
        this.radDropDownList1.DropDownListElement.TextBox.TextChanged += TextBox_TextChanged;
    }
     
    private void TextBox_TextChanged(object sender, EventArgs e)
    {
        this.radDropDownList1.DropDownListElement.ShowPopup();
        this.radTreeView1.Filter = this.radDropDownList1.DropDownListElement.TextBox.Text;
    }
     
    private void radDropDownList1_PopupOpened(object sender, EventArgs e)
    {
        RadDropDownListElement ddle = sender as RadDropDownListElement;
        ddle.Popup.MouseWheel -= ddle_MouseWheel;
        ddle.Popup.MouseWheel += ddle_MouseWheel;
    }
     
    private void ddle_MouseWheel(object sender, MouseEventArgs e)
    {
        DropDownPopupForm popup = sender as DropDownPopupForm;
        RadTreeView tree = popup.Controls[0] as RadTreeView;
        if (tree != null && mi != null)
        {
            mi.Invoke(tree.TreeViewElement, new object[] { e });
        }
    }
     
    private void radTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
    {
        this.radDropDownList1.DropDownListElement.ClosePopup();
        this.radDropDownList1.Text = this.radTreeView1.SelectedNodes[0].Text;
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready