Windows Develop Bookmark and Share   
 index > Windows Forms General > Custom TreeView Control in Windows Forms
 

Custom TreeView Control in Windows Forms

Hi,

I'm new to Windows Forms and are looking for some help. I would like to create my custom TreeView control based on the one provided by the framework.

I have derived from this control and added my own TextBox, so far so good.

NowI would like this TextBox to be rendered next to the node label. Doing it in asp.net (which is what I am used to), I would override the CreateChildControls() and Render() methods to include my TextBox.

How do you do this in a windows forms application? Is there a corresponding method to override, like in asp.net? Or is there another way of doing it?

d00mo  Tuesday, August 12, 2008 9:29 AM

Hi d00mo,

I am very clear about your problem. If you only want to let the users can edit the label of the TreeNode, it is very easy to handle. We just need to set the LabelEdit to true. Then when users double click the TreeNode, the TreeNode label is editable.

If you do need to add control to TreeNode, I would suggest use one control for all the TreeNodes and place the control near to the current TreeNode. This is because if we have a lot of controls on one form, the performance will be very low. Here is a sample about adding a ComboBox to TreeView control.

If you want to change the position of the ComboBox, you can change the bounds of the ComboBox by changing the arguments of the SetBounds method.

Code Snippet

protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)

{

……�/span> this.m_CurrentNode.ComboBox.SetBounds(

this.m_CurrentNode.Bounds.X + this.m_CurrentNode.Bounds.Width + 3,

this.m_CurrentNode.Bounds.Y - 2,

this.m_CurrentNode.Bounds.Width + 25,

this.m_CurrentNode.Bounds.Height);

……�/span> }

Let me know if this helps, if not, could you please show us more information?

Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Friday, August 15, 2008 3:35 AM

Hi d00mo,

I am very clear about your problem. If you only want to let the users can edit the label of the TreeNode, it is very easy to handle. We just need to set the LabelEdit to true. Then when users double click the TreeNode, the TreeNode label is editable.

If you do need to add control to TreeNode, I would suggest use one control for all the TreeNodes and place the control near to the current TreeNode. This is because if we have a lot of controls on one form, the performance will be very low. Here is a sample about adding a ComboBox to TreeView control.

If you want to change the position of the ComboBox, you can change the bounds of the ComboBox by changing the arguments of the SetBounds method.

Code Snippet

protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)

{

……�/span> this.m_CurrentNode.ComboBox.SetBounds(

this.m_CurrentNode.Bounds.X + this.m_CurrentNode.Bounds.Width + 3,

this.m_CurrentNode.Bounds.Y - 2,

this.m_CurrentNode.Bounds.Width + 25,

this.m_CurrentNode.Bounds.Height);

……�/span> }

Let me know if this helps, if not, could you please show us more information?

Best regards.
Rong-Chun Zhang

Windows Forms General FAQs
Windows Forms Data Controls and Databinding FAQs

Rong-Chun Zhang  Friday, August 15, 2008 3:35 AM

You can use google to search for other answers

Custom Search

More Threads

• Manual restore - weird rendering?
• BUG in VB.NET? Usercontrol and Enabled
• Context Menu's Events and Arguments
• Clipboard hangs for 5 seconds with Multithreading
• Keeping an image visible after form has been resized or drop menu impinges on display area
• .NET HTML WYSIWYG Control
• Which event should I use ???
• Drag and drop?
• Capture user Input?
• Implimenting scrolling on ScrollableControl derived control