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
.
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
.
private void tcombo_SelectedIndexChanged(object sender, EventArgs e)
{
current_tree_node.Text = tcombo.Text;
tcombo.Hide();
}
History
Version 1.0: 21/2/2005 (Posted).
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.