Please Help Me Understand This Bizarre Tree Entry Observation

T

Tom

My older system: Win2k, VS2005(Academic), .Net 2.0 SP1.

Windows.Forms Application: Two splitter panels, a TreeView (named:
"tree") in one panel populated with directory name nodes.

Logic for programmatically selecting a previously saved FullPath is
being called from the tree.Enter() event handler;

After expanding to a specific folder and selecting it (for testing
purposes I chose a specific folder that is level 4 depth) ... I
observe a difference between tabbing into the tree control and mouse
clicking into it. I have placed the following line at the beginning of
the Enter event handler:

Console.Writeline("tree.SelectedNode = {0}", tree.SelectedNode);

----------------------------------------------------
The problem >>>

When I tab into the tree control, above line output is:

tree.SelectedNode =

When I click into the tree control, the output is:

tree.SelectedNode = TreeNode: G:\

----------------------------------------------------
The "G" drive is correct for the folder selected. This subtle little
SelectedNode value difference is wreaking havoc on my code that
programmatically selects a previously saved folder location.

I've tried a variety of guesses aimed at gaining some control and
understanding of what is going on ... but all of them are failures and
discussing them only confuses the issue. :(

I might eventually stumble onto a novice programmer level solution ...
but I'd be so much better off understanding what is going on and how
to properly control the property settings of the TreeView object.

Specific guidance to the above problem would be wonderful !!

Additional TreeView advice or example code on programmatic selection
would be equally appreciated. Suggested texts, links, etc. I'm not
lazy ... but perhaps as evidenced from the hours I've spent searching
and the days of confusion this has caused me it is fair to say I'm not
exactly "gifted". ;)

** Thanks in advance for any help !! **

-- Tom
 
P

Peter Duniho

[...] I have placed the following line at the beginning of
the Enter event handler:

Console.Writeline("tree.SelectedNode = {0}", tree.SelectedNode);

----------------------------------------------------
The problem >>>

When I tab into the tree control, above line output is:

tree.SelectedNode =

When I click into the tree control, the output is:

tree.SelectedNode = TreeNode: G:\

Well, when you tab into the control, is there actually a node selected?
Or is there simply a focus rectangle around one of the nodes?

I would expect the SelectedNode property to be a reliable source of
information regarding what's selected, if anything. So if it's not
returning a node, it seems likely that no node is selected at that moment.

Barring that, you should post a concise-but-complete code sample that
reliably demonstrates the problem you're having.

Pete
 
T

Tom

Thanks Pete !

I will try to explore if somewhere in my other event handlers within
this project if somehow the SelectedNode becomes null. At this time
there is no concise way for me to duplicate the observation ... but I
will try. The observed problem is in a project that has grown to a few
thousand lines of code and there are a lot of interactions between the
panels.

Searching for the precise location where the SelectedNode becomes null
will hopefully reveal some additional insights into the combination of
events that I am trying to coordinate. I suffered immensely from using
too many events early on and have been trying to reduce the calling of
events as much as possible. Typical rookie mistake perhaps. Observe
something not behaving correctly, don't understand it, search through
the lists of events for something to cure the symptom ... all the
while not recognizing and treating the cause.

I've caught a few of my TreeView populating mistakes by writing out
detailed Nodes[].Name tables. I wish the texts I've read concentrated
more on troubleshooting rather than presenting a minimalist
pedagogical and well polished example. But then ... would the readers
appreciate it? Or the publishers print it?

Your comment has me re-energized and thinking again.

Thanks !!

-- Tom
 

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