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 : Nov 16th 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?

 

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

Sample :

http://files.syncfusion.com/support/Tools.Windows/KB/KB_ComboBoxBarItemTreeView/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
1826 04/30/2011 07/10/2014 WinForms XPToolbar
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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