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

TreeView with Combo

By , 23 Feb 2005
 

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

About the Author

Ahmed Mahmoud Mohammed
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralThx a lot!memberMember 432469818 Sep '08 - 19:09 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 24 Feb 2005
Article Copyright 2005 by Ahmed Mahmoud Mohammed
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid