We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to display TreeView as the dropdown of the ComboBox in XPMenus in the WinForms XPToolBar?

Platform: WinForms |
Control: XPToolbar |
Published Date: April 30, 2011 |
Last Revised Date: February 7, 2020

Display TreeView as the dropdown of the ComboBox inXPMenus

The XP Menus framework provides the flexibility to add detached toolbars through CommandBar that can host any .NET control. So, to achieve this we can add the Treeview control as the PopupControl of the ComboBoxDropDown and it can be added to the CommandBar of the XPMenus.

C#

private TreeNode FindNode(TreeNodeCollection nodes, string text)
{
   foreach (TreeNode child in nodes)
      if (child.Text == text)
         return child;
   foreach (TreeNode child in nodes)
   {
      TreeNode matched = this.FindNode(child.Nodes, text);
      if (matched != null)
         return matched;
   }
return null;
}
private void comboDropDown1_DropDown(object sender, EventArgs e)
{
   // Before the drop-down is shown, select a TreeNode based on the text in the combo.
   if (this.comboDropDown1.Text != String.Empty)
   {
      TreeNode matchedNode = this.FindNode(this.treeView1.Nodes, this.comboDropDown1.Text);
      this.treeView1.SelectedNode = matchedNode;
   }
}

VB

Private Function FindNode(ByVal nodes As TreeNodeCollection, ByVal text As String) As TreeNode
   For Each child As TreeNode In nodes
       If child.Text = text Then
          Return child
       End If
   Next child
   For Each child As TreeNode In nodes
       Dim matched As TreeNode = Me.FindNode(child.Nodes, text)
       If matched IsNot Nothing Then
          Return matched
       End If
   Next child
   Return Nothing
End Function
Private Sub comboDropDown1_DropDown(ByVal sender As Object, ByVal e As EventArgs) Handles comboDropDown1.DropDown
   '' Before the drop-down is shown, select a TreeNode based on the text in the combo.
   If Me.comboDropDown1.Text <> String.Empty Then
      Dim matchedNode As TreeNode = Me.FindNode(Me.treeView1.Nodes, Me.comboDropDown1.Text)
      Me.treeView1.SelectedNode = matchedNode
   End If
End Sub

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Ayman Metwally
Feb 11, 2019

Can you please reshare the link of this sample?

Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon