BinaryTreeViewComboBox
// BinaryComboBox - Base ComboBox class for implementing BinaryTreeViewComboBox class. //
public class BinaryTreeViewComboBox : BinaryComboBox
Inherits from / implements: BinaryComboBox
Remarks
// BinaryComboBox class represents the base class for BinaryTreeViewComboBox class. //
// Typically you do not need to use this class directly, since you are provided with more specialized class viz., BinaryTreeViewComboBox class. // //
Members at a glance
BinaryTreeViewComboBox | Initializes a new instance of BinaryTreeViewComboBox class. |
CustomDropDownWindowLocationPoint | Gets or sets a custom screen coordinate at which to locate the drop-down window. |
CustomImageForClosingDropDownWindow | Gets or sets a custom Image that is to be displayed as the drop-down window close button image. |
DisplayCloseWindowImage | Gets or sets a value indicating whether to display the "close window" image in the drop-down tree-view window. |
DisplayThisFromTreeView | Gets or sets the Combobox text display style. |
DropDownTreeViewInstance | Gets the TreeView object that is displayed in the drop-down window. |
DropDownWidth | Read-only here. The drop-down is a tree view sized to its content, so the inherited width setting has no effect and is hidden from the designer. |
DropDownWindowBorderColor | Gets or sets the Border color for the drop-down treeview window. |
DropDownWindowSize | Gets or sets the Size of the drop-down treeview window. |
SelectedNode | Gets the currently selected node. |
SelectedNodeIndex | Gets the currently selected node's index. |
SeperationCharacter | Gets or sets the separation character (expressed as a string) to be displayed between various node text items - when displaying the selected treeview text in the edit portion of the combobox control. |
SetControlTextUponNodeSelection | Gets or sets whether the control should set the combobox text area text, as and when the user selects a node, or should it be set only when the user double-clicks on a node / hits enter key on a node. |
ShowDropDownTreeViewWindowAfterAdjustingForVirtualAvailableScreenSpace | Gets or sets a value indicating whether the control should show drop-down treeview window after adjusting for virtual available screen space. |
TreeViewInstance | Gets or sets the implementation for ISupportTreeView interface, only if the treeview instance you are using is NOT TreeView. |
TreeViewNativeInstance | Sets the instance of your treeview object into the control, so it can be displayed as the treeview dropdown. |
Dispose | Releases the resources held by this BinaryTreeViewComboBox. |
OnDropDown | Raises the DropDown event. BinaryTreeViewComboBox overrides it so the control's own handling runs alongside the base behavior. |
PaintControlWithData | Draws the closed control showing the selected node, rather than the plain list item the base combo box would draw. |
RefreshPaint | Redraws the control face after the selected node changes, without going through a full layout pass. |
ReleaseChildDropDown | This method lets you to deterministically close the drop-down tree-view window. |
SetData | Refreshes the text shown on the closed control from the node currently selected in the tree. |
AboutToShowDropDownWindow | This event is raised just before the drop-down window (i.e the treeview window) of the combobox is about to be shown. |
DropDownWindowHidden | This event is raised just after the drop-down window (i.e the treeview window) of the combobox has been hidden/closed. |
TreeViewWindowKeyPressed | The event raised when a key is pressed, when the focus is in the treeview window. |
TreeViewWindowKeyUpOrDownEvent | The event raised for the KeyUp or KeyDown event, when the focus is in the treeview window. |
TreeViewWindowMouseEvent | The event raised when the mouse is clicked in the treeview window. |
Constructors
BinaryTreeViewComboBox
Initializes a new instance of BinaryTreeViewComboBox class.
Properties
CustomDropDownWindowLocationPoint
Gets or sets a custom screen coordinate at which to locate the drop-down window.
CustomImageForClosingDropDownWindow
Gets or sets a custom Image that is to be displayed as the drop-down window close button image.
Image object of your choice. The Width and Height of the custom image cannot exceed 14 pixels. If it does, the default image will be used and this property will automatically be set to null.
Note: If you set this property to null, the internal default image will be displayed as the window close image for the drop-down window.
DisplayCloseWindowImage
Gets or sets a value indicating whether to display the "close window" image in the drop-down tree-view window.
DisplayThisFromTreeView
Gets or sets the Combobox text display style.
SelectionDisplayStyle enumeration and SeperationCharacter property for more details.DropDownTreeViewInstance
Gets the TreeView object that is displayed in the drop-down window.
DropDownWidth
Read-only here. The drop-down is a tree view sized to its content, so the inherited width setting has no effect and is hidden from the designer.
DropDownWindowBorderColor
Gets or sets the Border color for the drop-down treeview window.
ControlText.DropDownWindowSize
Gets or sets the Size of the drop-down treeview window.
Size of your choice for the drop-down treeview window using this property.SelectedNode
Gets the currently selected node.
Note that this property is set to a valid node instance - only when you use the
TreeViewNative as your treeview control.SelectedNodeIndex
Gets the currently selected node's index.
Note that this property is set to a valid node index value only when you use the
TreeViewNative as your treeview control.SeperationCharacter
Gets or sets the separation character (expressed as a string) to be displayed between various node text items - when displaying the selected treeview text in the edit portion of the combobox control.
When you select a node in the drop-down treeview window, the selected text that is displayed in the combobox text portion depends on what style you have set in the
DisplayThisFromTreeView property. If you have chosen the DisplayFromTreeView.SelectedNode style, then the text of the selected node in the drop-down treeview will be displayed in the combobox.
If you have selected the DisplayFromTreeView.SelectedNodeAndAllChildNodes style, then the text of the selected node and all of its children element's text will be displayed.
When displaying the multiple text elements in the combobox, a separation character will be used to separate the various text elements from one-another. The default separation character is a comma (",").
You could change that to any other string, for example ":", by setting this property.
SetControlTextUponNodeSelection
Gets or sets whether the control should set the combobox text area text, as and when the user selects a node, or should it be set only when the user double-clicks on a node / hits enter key on a node.
ShowDropDownTreeViewWindowAfterAdjustingForVirtualAvailableScreenSpace
Gets or sets a value indicating whether the control should show drop-down treeview window after adjusting for virtual available screen space.
TreeViewInstance
Gets or sets the implementation for ISupportTreeView interface, only if the treeview instance you are using is NOT TreeView.
TreeView class with TreeViewNative class. and continue to setup your treeview as usual, and set the control's property TreeViewNative, and not this property. This way, you can use the internally defined / pre-written support for the ISuuportTreeView interface implementation. Only if you are not using TreeView control as the treeview object, then you will need to wrap that control into your custom class and implement ISupportTreeView interface, and pass it on to this property TreeViewInstance for display in TreeViewComboBox. The following is a sample implementation of the interface
ISupportTreeView interface. public class CustomTreeView : TreeView, BinarymissionTreeViewInterface.ISupportTreeView { BinarymissionTreeViewInterface.TreeNode treeNodeProxy = null; public CustomTreeView() : base() { treeNodeProxy = new Binarymission.WinFormControls.ListControls.InterfacesAndExtensionHelpers.TreeNode(); base.AfterSelect += new TreeViewEventHandler(CustomTreeView_AfterSelect); } void CustomTreeView_AfterSelect(object sender, TreeViewEventArgs e) { if (treeNodeProxy == null) return; treeNodeProxy.Text = e.Node.Text; treeNodeProxy.ParentTextItemsList = PrepareListFromNodes(e.Node, true); treeNodeProxy.ChildNodesItemsList = PrepareListFromNodes(e.Node, false); if (AfterSelect != null) { BinarymissionTreeViewInterface.TreeViewEventArgs te = new Binarymission.WinFormControls.ListControls.InterfacesAndExtensionHelpers.TreeViewEventArgs(); te.SelectedTreeNode = treeNodeProxy; AfterSelect(this, te); } } private List<string> PrepareListFromNodes(TreeNode node, bool parent) { List<string> textList = new List<string>(); if (parent) { TreeNode n = node.Parent; while (n != null) { textList.Add(n.Text); n = n.Parent; } } else { foreach (TreeNode n in node.Nodes) { textList.Add(n.Text); } } return textList; } public event BinarymissionTreeViewInterface.TreeViewEventHandler AfterSelect; }TreeViewNativeInstance
Sets the instance of your treeview object into the control, so it can be displayed as the treeview dropdown.
TreeView, then set this property, and NOT TreeViewInstance property. Prepare you treeview instance as usual, and set this property. Note that instaed of using TreeView use the TreeViewNative. Setup your Treeview control. This is just a simple construction. You could however build it any other manner as you would, like directly from data sources etc.
Note that if you are only the System.Windows.Forms.TreeView and want to pass on this to control to BinaryTreeViewComboBox display, then simply replace the TreeView with Binarymission.WinFormControls.ListControls.BinaryTreeViewComboBox.TreeViewNative and continue to use your treeview as usual. This way, you can use the internally defined / pre-written support for the ISuuportTreeView interface implementation.
Only if you are not using System.Windows.Forms.TreeView control as the treeview object, then you will need to wrap that control inot your custom class and implement ISupportTreeView interface. For implementing this interface, please refer to the help guide which comes with a sample class implementing this interface, and you can clone that in to your implementation.
A code example is provided below (in C# .NET):
Binarymission.WinFormControls.ListControls.BinaryTreeViewComboBox.TreeViewNative customTreeView = new Binarymission.WinFormControls.ListControls.BinaryTreeViewComboBox.TreeViewNative(); customTreeView.ImageIndex = -1; customTreeView.Name = "customTreeViewInstance"; customTreeView.SelectedImageIndex = -1; customTreeView.Size = new System.Drawing.Size(250, 350); customTreeView.TabIndex = 0; customTreeView.HideSelection = false; customTreeView.BorderStyle = BorderStyle.FixedSingle; customTreeView.ImageList = this.imageList1; TreeNode root = new TreeNode("Corporate"); root.ImageIndex = 0; root.SelectedImageIndex = 0; customTreeView.Nodes.AddRange(new System.Windows.Forms.TreeNode[]{root}); // Now add the child nodes to the root TreeNode projectnode = new TreeNode("Projects"); projectnode.ImageIndex = 1; projectnode.SelectedImageIndex = 1; root.Nodes.Add(projectnode); TreeNode NETNode = new TreeNode("On .NET"); NETNode.ImageIndex = 2; NETNode.SelectedImageIndex = 2; projectnode.Nodes.Add(NETNode); TreeNode temp1 = new TreeNode("Delivered (19)"); temp1.ImageIndex = 3; temp1.SelectedImageIndex = 3; NETNode.Nodes.Add(temp1); TreeNode temp2 = new TreeNode("Work-in-Progress (23)"); temp2.ImageIndex = 4; temp2.SelectedImageIndex = 4; NETNode.Nodes.Add(temp2); TreeNode temp3 = new TreeNode("System Study (8)"); temp3.ImageIndex = 1; temp3.SelectedImageIndex = 1; customTreeView.SelectedNode = temp3; NETNode.Nodes.Add(temp3); TreeNode temp4 = new TreeNode("Appraisals (7)"); temp4.ImageIndex = 2; temp4.SelectedImageIndex = 2; NETNode.Nodes.Add(temp4); TreeNode COMNode = new TreeNode("On COM+"); COMNode.ImageIndex = 3; COMNode.SelectedImageIndex = 3; projectnode.Nodes.Add(COMNode); TreeNode temp5 = new TreeNode("Proposal Phase (7)"); temp5.ImageIndex = 4; temp5.SelectedImageIndex = 4; COMNode.Nodes.Add(temp5); TreeNode temp6 = new TreeNode("Site Visit/Analysis (3)"); temp6.ImageIndex = 1; temp6.SelectedImageIndex = 1; COMNode.Nodes.Add(temp6); TreeNode temp7 = new TreeNode("W-I-P (2)"); temp7.ImageIndex = 2; temp7.SelectedImageIndex = 2; COMNode.Nodes.Add(temp7); TreeNode temp8 = new TreeNode("Delivered (41)"); temp8.ImageIndex = 3; temp8.SelectedImageIndex = 3; COMNode.Nodes.Add(temp8); TreeNode ConsultNode = new TreeNode("On-line Consultancy"); ConsultNode.ImageIndex = 4; ConsultNode.SelectedImageIndex = 4; projectnode.Nodes.Add(ConsultNode); TreeNode Assets = new TreeNode("Assets"); Assets.ImageIndex = 1; Assets.SelectedImageIndex = 1; root.Nodes.Add(Assets); TreeNode People = new TreeNode("People"); People.ImageIndex = 2; People.SelectedImageIndex = 2; root.Nodes.Add(People); TreeNode Documents = new TreeNode("Documents (Templates)"); Documents.ImageIndex = 3; Documents.SelectedImageIndex = 3; root.Nodes.Add(Documents); TreeNode Papers = new TreeNode("White Papers"); Papers.ImageIndex = 4; Papers.SelectedImageIndex = 4; Documents.Nodes.Add(Papers); TreeNode Appraisals = new TreeNode("Appraisals"); Appraisals.ImageIndex = 5; Appraisals.SelectedImageIndex = 5; Documents.Nodes.Add(Appraisals); customTreeView.TabIndex = 0; customTreeView.Scrollable = true; customTreeView.ExpandAll(); // You could set the size of the drop-down window, if you need. //Size sz = new Size(350, customTreeView.Height); //this.binaryTreeViewComboBox1.DropDownWindowSize = sz; customTreeView.BorderStyle = BorderStyle.None; this.binaryTreeViewComboBox1.ShowBorderAlways = true; this.binaryTreeViewComboBox1.TreeViewNativeInstance = customTreeView;
Methods
Dispose
Releases the resources held by this BinaryTreeViewComboBox.
- disposing
- true when called from
Dispose; false when called from the finalizer.
OnDropDown
Raises the DropDown event. BinaryTreeViewComboBox overrides it so the control's own handling runs alongside the base behavior.
- e
- The data for the event.
PaintControlWithData
Draws the closed control showing the selected node, rather than the plain list item the base combo box would draw.
- g
- The surface to draw on.
- bounds
- The bounds of the control face.
- Index
- The index of the selected item.
- isSelected
- true when the control is showing a selection.
- toEdit
- true when the face is being drawn for editing rather than display.
RefreshPaint
Redraws the control face after the selected node changes, without going through a full layout pass.
- g
- The surface to draw on.
- bounds
- The bounds of the control face.
- Index
- The index of the selected item.
- isSelected
- true when the control is showing a selection.
- toEdit
- true when the face is being drawn for editing rather than display.
ReleaseChildDropDown
This method lets you to deterministically close the drop-down tree-view window.
SetData
Refreshes the text shown on the closed control from the node currently selected in the tree.
Events
AboutToShowDropDownWindow
This event is raised just before the drop-down window (i.e the treeview window) of the combobox is about to be shown.
TreeViewWindowKeyPressed
The event raised when a key is pressed, when the focus is in the treeview window.
TreeViewWindowKeyUpOrDownEvent
The event raised for the KeyUp or KeyDown event, when the focus is in the treeview window.
TreeViewWindowMouseEvent
The event raised when the mouse is clicked in the treeview window.