[Winforms] Treeview events

T

timor.super

Hi group,

When I expand a treenode, I get this events in this order :

- AfterExpand
- AfterSelect
- NodeMouseClick

But I'm doing quite the same thing in each of this events, then, I do
my things 3 times altought I need only one time.

The problem is that I have to do this thing if I only select the node,
or if i only click on the node ; so depending on what i'm doing :

- click on the node (that is already selected) => my treatment is
doing 1 time (only the mouse click event is fired)
- click on the node (that is not selected) => 2 times (After select &
MouseClick)
- expand the node => 3 times

How can I make my treatment only one time and that all the 3 things
are covered ?

Thanks for your help
 
T

timor.super

Thanks for your answer. The "thing" is :
it's a treeview containing the files on the hard drive, so, deploy a
node load the files under the directory
Selecting the node, update the node with possible change on the hard
disk, clicking on the node too ...

When there's many files, the loading or updating (that is the same
task) can be quite long, that's why I would like to avoid loading this
too many times.

Any idea ?

[...]
The problem is that I have to do this thing if I only select the node,
or if i only click on the node ; so depending on what i'm doing :
- click on the node (that is already selected) => my treatment is
doing 1 time (only the mouse click event is fired)
- click on the node (that is not selected) => 2 times (After select &
MouseClick)
- expand the node => 3 times
How can I make my treatment only one time and that all the 3 things
are covered ?

You don't, not when you don't know that one event is necessarily going to 
follow another.  If the events can appear alone, then you can't make them  
depend on each other.

You don't describe what this "thing" you are doing is.  But it's bad  
design to have some "thing" you do in response to user input like this be 
something that can't be done repeatedly.  For example, any good UI design  
that uses both single clicks and double-clicks will always perform the  
single-click action first, even for a double-click event, because  
otherwise the UI winds up laggy at best, and confusing at worst.

So, hopefully your only concern here is one of performance, in which case 
the answer is "don't worry about it".  If it's somehow harmful to repeat  
the action, then you should rethink your user-interface design.

Pete
 
T

timor.super

I find your method quite hard.
It's strange that I need to watch the entire system to be aware of
files modification on a tree.
I won't load the entire tree at beginning too, it's taking too much
time ...

Is there a design pattern for treeview ?
 
T

timor.super

To each their own, I suppose.


I never suggested you need to watch the _entire_ system.  Each node could  
install its own handler for its own specific spot in the file system, if  
and only if that node is visible.


Again, I never suggested you do.

All that said, "my method" is not necessarily to use the FileSystemWatcher  
class.  That was but one suggestion I offered.  I think having a  
user-initiated refresh would be fine too.  But doing it simply because a  
node is selected?  Not only is that the root of your present problem, it  
seems overly eager and potentially confusing to the user.

Pete

Ok,

I understand better. I've used your suggestion to use a
FileSystemWatcher, and it's working good, I can improve my
reloading...

Thanks for your help

Best regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top