By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,132 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,132 IT Pros & Developers. It's quick & easy.

Updating Nodes in a treeview without deselecting current node

P: n/a
Tom
Hey,

I have a treeview control which i am reading and writing slots to (Its a
player manager for Delta Force Black Hawk Down).

At the moment, every 100ms it reads through the games memory to retreive
the player info, which i can parse. Problem is is that if you have an
item selected, when it clears and remakes all the nodes it deselects the
one selected, making it pretty useless to select players to view details.

Does anyone have a foolproof method to update a treeview while keeping
the currently selected node selected?
/// Begin Code

Dim L As Long
Dim hostvalue As Long
Dim player As Long
Dim name As String

hostvalue = ReadALong(&H7120C0)

tvPlayers.Nodes("root").Nodes.Clear()

For L = 0 To 49
player = hostvalue + (668 * L)
name = ReadAscii(player + 200, 16)
If name <"" Then
Dim newnode As TreeNode = New TreeNode
newnode.Text = L + 1 & ") " & name
newnode.Tag = player
tvPlayers.Nodes("root").Nodes.Add(newnode)
End If

Next L

Cheers

Tom
Jun 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jun 19, 11:07 am, Tom <tomrleigh...@gmail.comwrote:
Hey,

I have a treeview control which i am reading and writing slots to (Its a
player manager for Delta Force Black Hawk Down).

At the moment, every 100ms it reads through the games memory to retreive
the player info, which i can parse. Problem is is that if you have an
item selected, when it clears and remakes all the nodes it deselects the
one selected, making it pretty useless to select players to view details.

Does anyone have a foolproof method to update a treeview while keeping
the currently selected node selected?

/// Begin Code

Dim L As Long
Dim hostvalue As Long
Dim player As Long
Dim name As String

hostvalue = ReadALong(&H7120C0)

tvPlayers.Nodes("root").Nodes.Clear()

For L = 0 To 49
player = hostvalue + (668 * L)
name = ReadAscii(player + 200, 16)
If name <"" Then
Dim newnode As TreeNode = New TreeNode
newnode.Text = L + 1 & ") " & name
newnode.Tag = player
tvPlayers.Nodes("root").Nodes.Add(newnode)
End If

Next L

Cheers

Tom
Assuming there is a unique id for a player, why not store that value,
update the treeview, and then loop back through the nodes and re-
select it? Or possibly, instead of clearing all the nodes with
Nodes.Clear(), you could loop through and remove all but the selected
node. Then in your loop that adds the new nodes, skip adding the node
if the new node equals the selected node.

Thanks,

Seth Rowe

Jun 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.