How to scroll to found item in a treeview or a listview

Smokeywade

Member
Joined
Sep 11, 2007
Messages
22
Programming Experience
3-5
I currently have a search that is working 50% - it finds what to search for, but it does not scroll down or up to the item that is found. I've tried creating an a component class to do this with a scroll event argument...but no luck...any ideas.
On click do go to function
VB.NET:
Expand Collapse Copy
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        funcgetnode()
        If TextBox2.Text <> funcgetnode() Then
            MessageBox.Show("Nothing found")
        Else
            treeListView1.Focus()
        End If
    End Sub

do search
VB.NET:
Expand Collapse Copy
Function funcgetnode()
        Dim x As String = TextBox2.Text
        Dim i As Integer
        Dim nextnode As New TreeListNode
        Dim innode As New TreeListNode
        nextnode = nextnode.FirstChild
        For i = 0 To treeListView1.Nodes.Count - 1
            treeListView1.Nodes(i).Selected = False
            If treeListView1.Nodes(i).SubItems(0).ToString = x Then
                TextBox1.Text = "found"
                treeListView1.Nodes(i).Selected = True
                treelistview1.goTorow(i)
                funcgetnode = treeListView1.Nodes(i).SubItems(0).ToString
            End If
        Next
    End Function

compClass to go to row

VB.NET:
Expand Collapse Copy
Sub goTorow(ByVal row As Integer)
        If Not Me.DataBindings Is Nothing Then
            Me.scrollable = True
            Me.OnNodesChanged(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
        End If
    End Sub

Thanks
 
TreeView.SelectedNode Property
When you set this property, the specified node is scrolled into view and any parent nodes are expanded so that the specified node is visible.
ListView.EnsureVisible Method
Parameters: index
The zero-based index of the item to scroll into view.
ListViewItem.EnsureVisible Method
Ensures that the item is visible within the control, scrolling the contents of the control, if necessary.
All quotes from documentation.
 
Thanks...I've tried what you suggested, but for some reason it is not working - and I'm not getting an error message. Doesn't make any sense.
 
Back
Top