Invoking TreelistView events

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
robert.ganshorn
Posts: 54
Last visit: Sat Nov 25, 2023 8:17 pm

Invoking TreelistView events

Post by robert.ganshorn »

I have an 'afterselect' event for a treeview.

$tv_AfterSelect=[System.Windows.Forms.TreeViewEventHandler]{

..bunch of code

}

I want to invoke this event also from a button to refresh the tree, but I don't know how to exactly do that..

$tv_AfterSelect.Invoke($sender, $e)

What do I provide as the sender ($sender) and treelistarguments ($e) ?

Rob
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Invoking TreelistView events

Post by jvierra »

This should work:

$tv_AfterSelect.Invoke()
User avatar
robert.ganshorn
Posts: 54
Last visit: Sat Nov 25, 2023 8:17 pm

Re: Invoking TreelistView events

Post by robert.ganshorn »

Unfortunately this won't work because the event is expecting arguments passed to it. It throws an error on the invoke.

I worked around this by having the event just call a new function and pass treeview node name value. The other button event can do the same by just getting the current selected node name and passing that to the new function as well.

Events without the "=[System.Windows.Forms.TreeViewEventHandler]" can be invoked as you state.

Rob
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Invoking TreelistView events

Post by jvierra »

Use the sender and event from the current event.

$tv_AfterSelect.Invoke($this, $_)
This topic is 6 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked