Get TreeView nodes in sorted orderHow can I cancel a user's WPF TreeView click?WPF: TreeView inside a ComboBoxDeferred loading of TreeView in .NETSetting treeview background color in VB6 has a flaw - help?TreeView vertical scrollbar does not expand to the last node, last node is hidden?WPF TreeView with databinding hierarchical dataC# Intricate Treeview DesignOptimize search-as-you-type performance on a ExtJS treeviewhow to find node in WPF treeview?Assign custom properties to a node in TreeView windows forms?

Can somebody explain Brexit in a few child-proof sentences?

What will be the benefits of Brexit?

Hide Select Output from T-SQL

Teaching indefinite integrals that require special-casing

What's the purpose of "true" in bash "if sudo true; then"

How does residential electricity work?

Is HostGator storing my password in plaintext?

Efficiently merge handle parallel feature branches in SFDX

Student evaluations of teaching assistants

Products and sum of cubes in Fibonacci

How can I use the arrow sign in my bash prompt?

Can a monster with multiattack use this ability if they are missing a limb?

Why "be dealt cards" rather than "be dealing cards"?

Why are on-board computers allowed to change controls without notifying the pilots?

How to verify if g is a generator for p?

Displaying the order of the columns of a table

Can criminal fraud exist without damages?

Is it correct to write "is not focus on"?

Ways to speed up user implemented RK4

Was Spock the First Vulcan in Starfleet?

Is it okay / does it make sense for another player to join a running game of Munchkin?

What defines a dissertation?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

How do I define a right arrow with bar in LaTeX?



Get TreeView nodes in sorted order


How can I cancel a user's WPF TreeView click?WPF: TreeView inside a ComboBoxDeferred loading of TreeView in .NETSetting treeview background color in VB6 has a flaw - help?TreeView vertical scrollbar does not expand to the last node, last node is hidden?WPF TreeView with databinding hierarchical dataC# Intricate Treeview DesignOptimize search-as-you-type performance on a ExtJS treeviewhow to find node in WPF treeview?Assign custom properties to a node in TreeView windows forms?













2















We have a legacy application written in VB6 using the default Microsoft TreeView control to display hierarchical data. Since there's a lot of information in this TreeView we thought about implementing a small filter/search possibility for the users.



The first attempt was to toggle the visibility and only make nodes (and their parents) visible, that match the defined search. But that was impossible, since the default Microsoft TreeView control doesn't allow their nodes to be visible or invisible.



So the second attempt is to traverse all the nodes in the tree and ensure a node's visibility when it matches the defined search (and stop traversing). When the found node isn't the one the user is looking for he can "continue" the search and look for the next node that matches his criteria.



This works quite good so far, except for one little problem. The search doesn't work from top to bottom, since the tree is filled with data in random sort order and then sorted by setting the Sorted property of each node (legacy code). So the search is going through the randomly added nodes and the found nodes "jump" between the top level nodes (the Nodes collection of the TreeView contains all the nodes in the order they were added, not just the top level nodes and not in the order they are presented to the user).



Is there any way to get all the nodes of the tree in the order they are shown to the user? I don't like to change the legacy code that is filling the tree with data, and sorting the data before it is added to the TreeView might affect performance.



Please be aware that I'm talking about an application written in VB6, so there's no such thing as LINQ to traverse the nodes in the desired order.



Here's my searching code so far:



Private Sub cmdSearch_Click()
Dim oMatch As Node

Set oMatch = GetNextMatch

If Not (oMatch Is Nothing) Then
oMatch.EnsureVisible
oMatch.Selected = True
Me.TreeView1.SelectedItem = oMatch
Me.TreeView1.SetFocus
End If

End Sub

Private Function GetNextMatch() As Node
Dim lIndex As Long
Dim oResult As Node

For lIndex = mlLastFoundIndex + 1 To Me.TreeView1.Nodes.Count
If IsMatch(Me.TreeView1.Nodes(lIndex).Text) Then
Set oResult = Me.TreeView1.Nodes(lIndex)
mlLastFoundIndex = lIndex
Exit For
End If
Next lIndex

Set GetNextMatch = oResult
End Function

Private Sub txtSearch_Change()
mlLastFoundIndex = 0
End Sub









share|improve this question



















  • 3





    It sounds like you've already figured out a root cause of why this is hard - that the treeview itself is being used as the 'master' data structure for these operations. If instead you had a separate data structure you could implement anything you wanted and then just copy the results into the treeview. I can see where that might be a lot of work to an existing app, but sometimes that sort of refactoring turns out to be easier in the long run... less lurching from special case to special case (all of which are hard to anticipate)

    – DaveInCaz
    Mar 7 at 12:23












  • I agree with DaveInCaz but could you post the "search" code you're working with? I've worked with the control before and it can be quirky. The nodes I believe are indexed starting with 0.

    – Jimmy Smith
    Mar 7 at 16:13












  • No, the indexing with the Nodes starts with 1. I put the search code in the question. I'm looking for something that delivers the Me.TreeView1.Nodes in the order the nodes are presented to the user.

    – Nostromo
    Mar 8 at 5:58















2















We have a legacy application written in VB6 using the default Microsoft TreeView control to display hierarchical data. Since there's a lot of information in this TreeView we thought about implementing a small filter/search possibility for the users.



The first attempt was to toggle the visibility and only make nodes (and their parents) visible, that match the defined search. But that was impossible, since the default Microsoft TreeView control doesn't allow their nodes to be visible or invisible.



So the second attempt is to traverse all the nodes in the tree and ensure a node's visibility when it matches the defined search (and stop traversing). When the found node isn't the one the user is looking for he can "continue" the search and look for the next node that matches his criteria.



This works quite good so far, except for one little problem. The search doesn't work from top to bottom, since the tree is filled with data in random sort order and then sorted by setting the Sorted property of each node (legacy code). So the search is going through the randomly added nodes and the found nodes "jump" between the top level nodes (the Nodes collection of the TreeView contains all the nodes in the order they were added, not just the top level nodes and not in the order they are presented to the user).



Is there any way to get all the nodes of the tree in the order they are shown to the user? I don't like to change the legacy code that is filling the tree with data, and sorting the data before it is added to the TreeView might affect performance.



Please be aware that I'm talking about an application written in VB6, so there's no such thing as LINQ to traverse the nodes in the desired order.



Here's my searching code so far:



Private Sub cmdSearch_Click()
Dim oMatch As Node

Set oMatch = GetNextMatch

If Not (oMatch Is Nothing) Then
oMatch.EnsureVisible
oMatch.Selected = True
Me.TreeView1.SelectedItem = oMatch
Me.TreeView1.SetFocus
End If

End Sub

Private Function GetNextMatch() As Node
Dim lIndex As Long
Dim oResult As Node

For lIndex = mlLastFoundIndex + 1 To Me.TreeView1.Nodes.Count
If IsMatch(Me.TreeView1.Nodes(lIndex).Text) Then
Set oResult = Me.TreeView1.Nodes(lIndex)
mlLastFoundIndex = lIndex
Exit For
End If
Next lIndex

Set GetNextMatch = oResult
End Function

Private Sub txtSearch_Change()
mlLastFoundIndex = 0
End Sub









share|improve this question



















  • 3





    It sounds like you've already figured out a root cause of why this is hard - that the treeview itself is being used as the 'master' data structure for these operations. If instead you had a separate data structure you could implement anything you wanted and then just copy the results into the treeview. I can see where that might be a lot of work to an existing app, but sometimes that sort of refactoring turns out to be easier in the long run... less lurching from special case to special case (all of which are hard to anticipate)

    – DaveInCaz
    Mar 7 at 12:23












  • I agree with DaveInCaz but could you post the "search" code you're working with? I've worked with the control before and it can be quirky. The nodes I believe are indexed starting with 0.

    – Jimmy Smith
    Mar 7 at 16:13












  • No, the indexing with the Nodes starts with 1. I put the search code in the question. I'm looking for something that delivers the Me.TreeView1.Nodes in the order the nodes are presented to the user.

    – Nostromo
    Mar 8 at 5:58













2












2








2


1






We have a legacy application written in VB6 using the default Microsoft TreeView control to display hierarchical data. Since there's a lot of information in this TreeView we thought about implementing a small filter/search possibility for the users.



The first attempt was to toggle the visibility and only make nodes (and their parents) visible, that match the defined search. But that was impossible, since the default Microsoft TreeView control doesn't allow their nodes to be visible or invisible.



So the second attempt is to traverse all the nodes in the tree and ensure a node's visibility when it matches the defined search (and stop traversing). When the found node isn't the one the user is looking for he can "continue" the search and look for the next node that matches his criteria.



This works quite good so far, except for one little problem. The search doesn't work from top to bottom, since the tree is filled with data in random sort order and then sorted by setting the Sorted property of each node (legacy code). So the search is going through the randomly added nodes and the found nodes "jump" between the top level nodes (the Nodes collection of the TreeView contains all the nodes in the order they were added, not just the top level nodes and not in the order they are presented to the user).



Is there any way to get all the nodes of the tree in the order they are shown to the user? I don't like to change the legacy code that is filling the tree with data, and sorting the data before it is added to the TreeView might affect performance.



Please be aware that I'm talking about an application written in VB6, so there's no such thing as LINQ to traverse the nodes in the desired order.



Here's my searching code so far:



Private Sub cmdSearch_Click()
Dim oMatch As Node

Set oMatch = GetNextMatch

If Not (oMatch Is Nothing) Then
oMatch.EnsureVisible
oMatch.Selected = True
Me.TreeView1.SelectedItem = oMatch
Me.TreeView1.SetFocus
End If

End Sub

Private Function GetNextMatch() As Node
Dim lIndex As Long
Dim oResult As Node

For lIndex = mlLastFoundIndex + 1 To Me.TreeView1.Nodes.Count
If IsMatch(Me.TreeView1.Nodes(lIndex).Text) Then
Set oResult = Me.TreeView1.Nodes(lIndex)
mlLastFoundIndex = lIndex
Exit For
End If
Next lIndex

Set GetNextMatch = oResult
End Function

Private Sub txtSearch_Change()
mlLastFoundIndex = 0
End Sub









share|improve this question
















We have a legacy application written in VB6 using the default Microsoft TreeView control to display hierarchical data. Since there's a lot of information in this TreeView we thought about implementing a small filter/search possibility for the users.



The first attempt was to toggle the visibility and only make nodes (and their parents) visible, that match the defined search. But that was impossible, since the default Microsoft TreeView control doesn't allow their nodes to be visible or invisible.



So the second attempt is to traverse all the nodes in the tree and ensure a node's visibility when it matches the defined search (and stop traversing). When the found node isn't the one the user is looking for he can "continue" the search and look for the next node that matches his criteria.



This works quite good so far, except for one little problem. The search doesn't work from top to bottom, since the tree is filled with data in random sort order and then sorted by setting the Sorted property of each node (legacy code). So the search is going through the randomly added nodes and the found nodes "jump" between the top level nodes (the Nodes collection of the TreeView contains all the nodes in the order they were added, not just the top level nodes and not in the order they are presented to the user).



Is there any way to get all the nodes of the tree in the order they are shown to the user? I don't like to change the legacy code that is filling the tree with data, and sorting the data before it is added to the TreeView might affect performance.



Please be aware that I'm talking about an application written in VB6, so there's no such thing as LINQ to traverse the nodes in the desired order.



Here's my searching code so far:



Private Sub cmdSearch_Click()
Dim oMatch As Node

Set oMatch = GetNextMatch

If Not (oMatch Is Nothing) Then
oMatch.EnsureVisible
oMatch.Selected = True
Me.TreeView1.SelectedItem = oMatch
Me.TreeView1.SetFocus
End If

End Sub

Private Function GetNextMatch() As Node
Dim lIndex As Long
Dim oResult As Node

For lIndex = mlLastFoundIndex + 1 To Me.TreeView1.Nodes.Count
If IsMatch(Me.TreeView1.Nodes(lIndex).Text) Then
Set oResult = Me.TreeView1.Nodes(lIndex)
mlLastFoundIndex = lIndex
Exit For
End If
Next lIndex

Set GetNextMatch = oResult
End Function

Private Sub txtSearch_Change()
mlLastFoundIndex = 0
End Sub






vb6 treeview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 5:56







Nostromo

















asked Mar 7 at 11:42









NostromoNostromo

477214




477214







  • 3





    It sounds like you've already figured out a root cause of why this is hard - that the treeview itself is being used as the 'master' data structure for these operations. If instead you had a separate data structure you could implement anything you wanted and then just copy the results into the treeview. I can see where that might be a lot of work to an existing app, but sometimes that sort of refactoring turns out to be easier in the long run... less lurching from special case to special case (all of which are hard to anticipate)

    – DaveInCaz
    Mar 7 at 12:23












  • I agree with DaveInCaz but could you post the "search" code you're working with? I've worked with the control before and it can be quirky. The nodes I believe are indexed starting with 0.

    – Jimmy Smith
    Mar 7 at 16:13












  • No, the indexing with the Nodes starts with 1. I put the search code in the question. I'm looking for something that delivers the Me.TreeView1.Nodes in the order the nodes are presented to the user.

    – Nostromo
    Mar 8 at 5:58












  • 3





    It sounds like you've already figured out a root cause of why this is hard - that the treeview itself is being used as the 'master' data structure for these operations. If instead you had a separate data structure you could implement anything you wanted and then just copy the results into the treeview. I can see where that might be a lot of work to an existing app, but sometimes that sort of refactoring turns out to be easier in the long run... less lurching from special case to special case (all of which are hard to anticipate)

    – DaveInCaz
    Mar 7 at 12:23












  • I agree with DaveInCaz but could you post the "search" code you're working with? I've worked with the control before and it can be quirky. The nodes I believe are indexed starting with 0.

    – Jimmy Smith
    Mar 7 at 16:13












  • No, the indexing with the Nodes starts with 1. I put the search code in the question. I'm looking for something that delivers the Me.TreeView1.Nodes in the order the nodes are presented to the user.

    – Nostromo
    Mar 8 at 5:58







3




3





It sounds like you've already figured out a root cause of why this is hard - that the treeview itself is being used as the 'master' data structure for these operations. If instead you had a separate data structure you could implement anything you wanted and then just copy the results into the treeview. I can see where that might be a lot of work to an existing app, but sometimes that sort of refactoring turns out to be easier in the long run... less lurching from special case to special case (all of which are hard to anticipate)

– DaveInCaz
Mar 7 at 12:23






It sounds like you've already figured out a root cause of why this is hard - that the treeview itself is being used as the 'master' data structure for these operations. If instead you had a separate data structure you could implement anything you wanted and then just copy the results into the treeview. I can see where that might be a lot of work to an existing app, but sometimes that sort of refactoring turns out to be easier in the long run... less lurching from special case to special case (all of which are hard to anticipate)

– DaveInCaz
Mar 7 at 12:23














I agree with DaveInCaz but could you post the "search" code you're working with? I've worked with the control before and it can be quirky. The nodes I believe are indexed starting with 0.

– Jimmy Smith
Mar 7 at 16:13






I agree with DaveInCaz but could you post the "search" code you're working with? I've worked with the control before and it can be quirky. The nodes I believe are indexed starting with 0.

– Jimmy Smith
Mar 7 at 16:13














No, the indexing with the Nodes starts with 1. I put the search code in the question. I'm looking for something that delivers the Me.TreeView1.Nodes in the order the nodes are presented to the user.

– Nostromo
Mar 8 at 5:58





No, the indexing with the Nodes starts with 1. I put the search code in the question. I'm looking for something that delivers the Me.TreeView1.Nodes in the order the nodes are presented to the user.

– Nostromo
Mar 8 at 5:58












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042961%2fget-treeview-nodes-in-sorted-order%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042961%2fget-treeview-nodes-in-sorted-order%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко