title: Fast scrolling in Delphi's Virtual Treeview
body: <p><strong>[This is an updated version of a question posted earlier, the previous title was <em>Selecting node by index in Delphi’s Virtual Treeview</em>.]</strong></p>
  
  <p>After the better part of a day, I believe I've got the Virtual Treeview component (powerful but complex) working in a simple two table data aware fashion.  </p>
  
  <p>Now, I'm trying to simply select the 1,512th (for instance) of the top-level nodes.  I can't see any way to do this other than getting the first top-level node and then calling GetNextSibling 1,511 in a loop.</p>
  
  <p>This seems needlessly involved.  Is there a simpler way?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Because initializing the nodes in my tree requires database access, initializing all the nodes at startup is not feasible.  When the user starts with form with no record already selected, that's fine.  As the user scrolls around the tree, enough nodes are populated to display the current window into the tree and the performance is fine.</p>
  
  <p>When the user starts the form in dialog mode with a database record already selected, I must advance the tree to that node before the user sees the form.  This is a problem because, if the record is towards the end of the tree, it can take ten seconds as I walk the tree from the first node.  Each time I can GetNextSibling(), a node is initialized, even though the vast majority of those nodes are not displayed to the user.  I would prefer to defer the initialization of those nodes to the point at which they become visible to the user.</p>
  
  <p>I know that there must be a better way, because if I open the tree without a record selected and use the vertical scroll bar to move, in a single operation, to the middle of the tree then the correct nodes are displayed <em>without having to initialize the nodes I skipped over</em>.</p>
  
  <p>This is the effect I'd like to achieve when opening the tree with a record selected.  I know the index of the node I want to go to, but if I can't get there by index I could do a binary search on the tree assuming I can jump some number of nodes backwards and forwards (similar to scrolling directly to the middle of the tree).</p>
  
  <p>Alternatively, perhaps there is some State setting I can make to the tree view that will leave the intermediate nodes uninitialized as I traverse the grid.  I've tried Begin/End Update and that doesn't seem to do the trick.</p>