Click here to Skip to main content
Click here to Skip to main content

TreeView with Combo

, 23 Feb 2005
Rate this:
Please Sign up or sign in to vote.
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.

//
// 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.

//
// 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

Share

About the Author

Ahmed Mahmoud Mohammed

United States United States
No Biography provided

Comments and Discussions

 
GeneralThx a lot! PinmemberMember 432469818-Sep-08 19:09 
Generalvery good idea Pinmemberburlotjy12-Mar-07 4:36 
GeneralGood PinmemberBabuChellathurai8-Jan-07 23:13 
GeneralTreeNode as Text + ComboBox PinmemberAniket Salunkhe20-Sep-06 21:59 
GeneralSolve this problem PinmemberDragon Pig23-May-05 17:07 
GeneralError!!!!! PinmemberDragon Pig23-May-05 16:58 
GeneralNeeds more (of everything) Pinmembergxdata11-Mar-05 21:38 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 24 Feb 2005
Article Copyright 2005 by Ahmed Mahmoud Mohammed
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid