How do I handle a click event using the ObjectListView library?

499 views Asked by At

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

There are 1 answers

2
Robert Harvey On BEST ANSWER

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;