473,480 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: [Winforms] Treeview events

On Sat, 27 Sep 2008 12:02:04 -0700, <ti*********@gmail.comwrote:
[...]
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
Sep 27 '08 #1
5 2022
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 ?

On 27 sep, 22:47, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
On Sat, 27 Sep 2008 12:02:04 -0700, <timor.su...@gmail.comwrote:
[...]
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
Sep 27 '08 #2
On Sat, 27 Sep 2008 13:58:20 -0700, <ti*********@gmail.comwrote:
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 ?
Yes. Don't do that. :)

Instead, your nodes should retrieve the data as needed according to
visibility and changes to the directory. You can use FileSystemWatcher as
a way to monitor the latter; it's not perfect (rapid changes can overwhelm
it, especially if you're not careful to keep your event handlers simple),
but it'd be automatic rather than relying on user input and would avoid
the redundancy

If you insist on relying on user input to decide when to refresh, don't
make it based on selection. Retrieve the data as needed according to
visibility, and then provide the user with an explicit option to refresh
the data (e.g. context menu).

One final option, if you insist on this redundant behavior, is to handle
the updating in a worker thread and only start it again if you're not
already processing that node. Of course, each node would have to keep
track of whether it's waiting for such a worker thread to finish updating
it, but that's not hard.

Pete
Sep 27 '08 #3
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 ?

On 27 sep, 23:08, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
On Sat, 27 Sep 2008 13:58:20 -0700, <timor.su...@gmail.comwrote:
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 ?

Yes. *Don't do that. *:)

Instead, your nodes should retrieve the data as needed according to *
visibility and changes to the directory. *You can use FileSystemWatcheras *
a way to monitor the latter; it's not perfect (rapid changes can overwhelm *
it, especially if you're not careful to keep your event handlers simple),*
but it'd be automatic rather than relying on user input and would avoid *
the redundancy

If you insist on relying on user input to decide when to refresh, don't *
make it based on selection. *Retrieve the data as needed according to *
visibility, and then provide the user with an explicit option to refresh *
the data (e.g. context menu).

One final option, if you insist on this redundant behavior, is to handle *
the updating in a worker thread and only start it again if you're not *
already processing that node. *Of course, each node would have to keep *
track of whether it's waiting for such a worker thread to finish updating*
it, but that's not hard.

Pete
Sep 28 '08 #4
On Sun, 28 Sep 2008 00:10:24 -0700, <ti*********@gmail.comwrote:
I find your method quite hard.
To each their own, I suppose.
It's strange that I need to watch the entire system to be aware of
files modification on a tree.
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.
I won't load the entire tree at beginning too, it's taking too much
time ...
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
Sep 28 '08 #5
On 28 sep, 09:37, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
On Sun, 28 Sep 2008 00:10:24 -0700, <timor.su...@gmail.comwrote:
I find your method quite hard.

To each their own, I suppose.
It's strange that I need to watch the entire system to be aware of
files modification on a tree.

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.
I won't load the entire tree at beginning too, it's taking too much
time ...

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
Sep 29 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
8387
by: (Pete Cresswell) | last post by:
I've got KeyDown coding and it fires when other keys are pressed, but when Enter is pressed, nothing. I'd like to support the (standard?) Windows behavior of executing DblClick processing when...
5
3898
by: rh | last post by:
I created a user control that is made up of a TreeView and a VScrollBar. I set the TreeView.FullRowSelect = True and it works as expected (full row is visible, appears on top of everything else)...
4
3499
by: Hazz | last post by:
I am using the Winforms Treeview right out of the toolbox with all the default settings. It looks very boring. What can I do to dress it up and make it look at least kind of cool? I remember...
0
1458
by: stardust | last post by:
Hi everyone, Within a Winform application, a treeview is contained in a User Control and the User Control is then located within a splitview. When the UserControl added some nodes into the...
0
1320
by: Corky Whiteboard | last post by:
I have a Winforms treeview with subclassed treenodes. The treeview has "ShowNodeToolTips" set to true. The text is showing for each node, but it is not formatted 'pretty' - it comes out in one...
5
3804
by: brian.wilson4 | last post by:
Our group is currently comparing winforms vs webforms.....app is Corp LAN based - we have control of desktops.....Below is pros and cons list we have come up with - if anything strikes you as...
1
2214
by: echuck66 | last post by:
Hi, I have a Winforms 2.0 project that I'm working on that involves populating a treeview control from data contained in a fairly large dataset that has to be refreshed periodically. I have no...
4
4978
by: frostbb | last post by:
I have a C# WinForms treeview with 20 or so 'level 0' nodes. My users will normally have 2 of the 'level 0' branches open down to a '5th level' selected node. The users will make updates to...
1
6151
by: renuami | last post by:
Hello Please advise .... I do not know in which section i should be posting Winforms Questions. There is not Option. So i am posting it here... apologize for any inconvinence..... This is...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.