Updating Nodes in a treeview without deselecting current node

T

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
 
R

rowe_newsgroups

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
 

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