Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

node object not being set

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
What-ho,

OK, here we go....

I've got a TreeView control full of Node objects, which I have to peform an update on (I'm just populating it from a database, so I go through the population function again). Before the update takes place, one of the nodes is going to have been selected by the user (aggravating fool) and performing the update loses which node object was selected. To get around this, I set a node object variable to whatever the TreeView.SelectedItem is and then perform the update function. After updating the TreeView, I then attempt to set the TreeView.SelectedItem to the Node object I set before the update, like this:

Set TreeView.SelectedItem = nodUserSelected

where nodUserSelected is the preset node object.

However, despite the fact that the TreeView object is populated and the Node object variable is set and contains a valid node object which may be found in the TreeView.Nodes collection, it fails to set the selected item. This results in an object error when I attempt to set the selected item to be viewable, like this:

TreeView.SelectedItem.EnsureVisible

which is understandable, as the SelectedItem object is currently set to Nothing.

So why's that then?


Cheerio,

Paul
[sig][/sig]
 
Hi Paul,

I would imagine that your populate function clears the tree first?

So when that happens nodUserSelected won't be pointing to anything.... (the object to which it referred has been destroyed...)

Can you do it like a list box and save a ListIndex property or similar?
[sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
What-ho Mike,

To coin a phrase, &quot;Oh!&quot;...

I didn't think it was working like that at all. I thought that doing the whole Set Object = AnotherObject thing was actually sort of passing the object in question to the object variable by value, thus creating two independant instances of the same object.

Before I attempt my

Set TreeView.SelectedItem = nodUserSelected

the TypeName() function returns nodUserSelected as being of type INode, so I assumed that nodUserSelected was a fully independant node object. Certainly, it's default .text property returns the same as the previous .SelectedItem, despite the fact that I do, indeed, perform a TreeView.Nodes.Clear method as part of my update function.

I absolutely have to use a TreeView control, so do you know of any way of using my nodUserSelected object variable as an independant object rather than as a reference to another object?


Objectionable all of this, isn't it? :)


Thanks for your help,

Paul
[sig][/sig]
 
What-ho,

I see what you mean now...although I've set an object variable from the .SelectedItem object, it still relies on being associated with the TreeView control for a number if its properties. When these properties are no longer available, I can't use this object to explicitly set the .SelectedItem object, which is a pain :(

By doing this, though;

for each nodNodeItem in TreeView.Nodes
if nodNodeItem.Key = nodUserSelected.Key then
set TreeView.SelectedItem = nodNodeItem
end if
next


I get around the problem, although I only really need to keep a long variable with the unique key in it to find the user selected node item again, rather than assigning the .SelectedItem to an object variable.

That meant changing more code, though, and I'm inherently lazy :)


Thanks for your help,

Cheerio,

Paul
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top