0

I'm trying to use TreeListView, and i saw this post: How to create a MultiColumn treeview like this in C# Winforms app?. But i don't understand how handle event when i click on tree node. Could you help me?

i've tried to add event like this to form:

private void treeListView_Click(object sender, EventArgs e){
    Debug.Print("HI");
}

but it doesn't works.

Thanks to @Robert Harvey answer, i added

treeListView.CellClick += treeListView_CellClick; into FillTree method, where

private void treeListView_CellClick(object sender, BrightIdeasSoftware.CellClickEventArgs e)
        {
            Debug.Print("hi");
        }

1 Answer 1

0

That post uses the ObjectListView library. If you download the source code for that library, open it in Visual Studio and examine Events.cs, you'll find this, in the partial class for TreeListView:

/// <summary>
/// This event is triggered when user input requests the expansion of a list item.
/// </summary>
[Category("ObjectListView"),
Description("This event is triggered when a branch is about to expand.")]
public event EventHandler<TreeBranchExpandingEventArgs> Expanding;

/// <summary>
/// This event is triggered when user input requests the collapse of a list item.
/// </summary>
[Category("ObjectListView"),
Description("This event is triggered when a branch is about to collapsed.")]
public event EventHandler<TreeBranchCollapsingEventArgs> Collapsing;

/// <summary>
/// This event is triggered after the expansion of a list item due to user input.
/// </summary>
[Category("ObjectListView"),
Description("This event is triggered when a branch has been expanded.")]
public event EventHandler<TreeBranchExpandedEventArgs> Expanded;

/// <summary>
/// This event is triggered after the collapse of a list item due to user input.
/// </summary>
[Category("ObjectListView"),
Description("This event is triggered when a branch has been collapsed.")]
public event EventHandler<TreeBranchCollapsedEventArgs> Collapsed;

There's also a bunch of events defined in that file for the ObjectListView class itself, including this one:

/// <summary>
/// Triggered when a cell is left clicked.
/// </summary>
[Category("ObjectListView"),
Description("This event is triggered when the user left clicks a cell.")]
public event EventHandler<CellClickEventArgs> CellClick;
Sign up to request clarification or add additional context in comments.

2 Comments

ok, but if i add to form code objectListView's event like this: private void treeListView_Click(object sender, EventArgs e) { Debug.Print("ciao"); } it doesnt work
Note that you can write event handlers all day long, but you still have to hook them up to get them to work. Something like MyTreeView.CellClick += new EventHandler(CellClick); See here for more information about working with events.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.