Microsoft KB Archive/153026

= How To Show a ListView or TreeView Item Programmatically =

Article ID: 153026

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q153026



SUMMARY
Depending on the size of a ListView or TreeView control, not all ListItem or Node objects may be visible at one time. It is often desirable to control programmatically when a given ListItem or Node object is visible to a user. This article explains how to accomplish this functionality with both the ListView and TreeView controls.



MORE INFORMATION
Both the ListItem and Node objects have a method named "EnsureVisible'. To show an object all that needs to be done is to call this method from the object to be made visible. This will cause the ListView or TreeView to scroll in such a way that the specified node is visible on screen. A TreeView node that happens to be embedded beneath multiple, unexpanded levels will be made visible by expanding all necessary levels of the TreeView. If the ListItem or Node is already visible, no change will occur.

Step-By-Step Example
 Start Visual Basic 4.0. Form1 is created by default. Add a single ListView control to the form.  Add the following code to Form1: Option Explicit

Private Sub Form_Click Dim i As Integer

i = CInt(InputBox$("Enter number of node:")) ListView1.ListItems(i).EnsureVisible End Sub

Private Sub Form_Load Dim lv As ListItem Dim i As Integer

For i = 1 To 75 Set lv = ListView1.ListItems.Add(,, "item " & i)      Next i   End Sub

 Press the F5 key or select Start from the Run menu to start the application. Click once on the form to show the input box, and then enter the number of the ListItem object to be made visible. Press OK to execute an EnsureVisible method on the ListItem object specified by the user-entered index number.

Additional query words: 4.00 vb4win vb432

Keywords: KB153026

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.