Click here to Skip to main content
15,885,365 members
Articles / Programming Languages / C#
Article

TreeView with Combo

Rate me:
Please Sign up or sign in to vote.
2.92/5 (20 votes)
23 Feb 2005 81K   1.6K   30   7
A control that makes users able to select predefined values from a ComboBox instead of editing them inside a TreeView.

Sample Image

Introduction

This control makes users able to select predefined values from a ComboBox instead of editing them inside a TreeView.

Background

The reader is expected to have basic Object Oriented concepts and awareness in C# coding.

Using the code

Just add the control to your form in design mode or in run time. There is a property in the control called "combobox". It exposes the ComboBox that will appear when editing in the tree. Just fill the data source of the ComboBox. Do not forget to enable editing in the TreeView!!

The sample demo has all of this in brief.

All I did in the control was to inherit from the class "TreeView" of the .NET Framework and override the OnBeforeLabelEdit method of the class to show the ComboBox.

C#
//
// Show combobox before editing in treeview //
protected override void OnBeforeLabelEdit (NodeLabelEditEventArgs e)
{ 
  current_tree_node = e.Node;
  tcombo.Bounds = e.Node.Bounds; tcombo.Show();
}

Then I handled the event SelectedIndexChanged of the ComboBox to set the TreeView label text with the selected text from the ComboBox.

C#
//
// Show combobox text in the treeview label text
//
private void tcombo_SelectedIndexChanged(object sender, EventArgs e)
{
  current_tree_node.Text = tcombo.Text;
  tcombo.Hide();
}

History

Version 1.0: 21/2/2005 (Posted).

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThx a lot! Pin
Member 432469818-Sep-08 19:09
Member 432469818-Sep-08 19:09 
Generalvery good idea Pin
burlotjy12-Mar-07 4:36
burlotjy12-Mar-07 4:36 
GeneralGood Pin
BabuChellathurai8-Jan-07 23:13
BabuChellathurai8-Jan-07 23:13 
GeneralTreeNode as Text + ComboBox Pin
Andy Rama20-Sep-06 21:59
Andy Rama20-Sep-06 21:59 
GeneralSolve this problem Pin
Member 198784623-May-05 17:07
Member 198784623-May-05 17:07 
GeneralError!!!!! Pin
Member 198784623-May-05 16:58
Member 198784623-May-05 16:58 
GeneralNeeds more (of everything) Pin
gxdata11-Mar-05 21:38
gxdata11-Mar-05 21:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.