473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

40
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
Expand|Select|Wrap|Line Numbers
  1.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.  
  3.         funcgetnode()
  4.         If TextBox2.Text <> funcgetnode() Then
  5.             MessageBox.Show("Nothing found")
  6.         Else
  7.             treeListView1.Focus()
  8.         End If
  9.     End Sub
do search
Expand|Select|Wrap|Line Numbers
  1. Function funcgetnode()
  2.         Dim x As String = TextBox2.Text
  3.         Dim i As Integer
  4.         Dim nextnode As New TreeListNode
  5.         Dim innode As New TreeListNode
  6.         nextnode = nextnode.FirstChild
  7.         For i = 0 To treeListView1.Nodes.Count - 1
  8.             treeListView1.Nodes(i).Selected = False
  9.             If treeListView1.Nodes(i).SubItems(0).ToString = x Then
  10.                 TextBox1.Text = "found"
  11.                 treeListView1.Nodes(i).Selected = True
  12.                 treelistview1.goTorow(i)
  13.                 funcgetnode = treeListView1.Nodes(i).SubItems(0).ToString
  14.             End If
  15.         Next
  16.     End Function
compClass to go to row

Expand|Select|Wrap|Line Numbers
  1. Sub goTorow(ByVal row As Integer)
  2.         If Not Me.DataBindings Is Nothing Then
  3.             Me.scrollable = True
  4.             Me.OnNodesChanged(Me, New ScrollEventArgs(ScrollEventType.LargeIncrement, row))
  5.         End If
  6.     End Sub
Thanks
Oct 23 '07 #1
7 7121
Plater
7,872 Expert 4TB
Setting the SelectedNode of your treeview will cause it to scroll.
I just did it.
Oct 23 '07 #2
KA NMC
40
I'm not understanding what you mean. Wouldnt the found item be the selectednode?

???
Expand|Select|Wrap|Line Numbers
  1. treeview1.selectednodes(0) = treeview1.nodes(i)
sorry if I'm a little lost on this one

Setting the SelectedNode of your treeview will cause it to scroll.
I just did it.
Oct 23 '07 #3
Plater
7,872 Expert 4TB
Uhhh huh?

I just know that whatever node I tell to be the SelectedNode on my treeview, the treeview will scroll it's way to that node and select it.
Oct 23 '07 #4
KA NMC
40
Ohhhhh....I get it now

Thanks once again...

Uhhh huh?

I just know that whatever node I tell to be the SelectedNode on my treeview, the treeview will scroll it's way to that node and select it.
Oct 23 '07 #5
KA NMC
40
I just wanted to say that I finally figured this out...I had to inherit the object in a component class - and then get each items row number - a bit confusing but here is the code

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To treeListView1.Nodes.Count - 1
  2.                 treeListView1.Nodes(i).Selected = False
  3.                 If treeListView1.Nodes(i).SubItems(0).ToString = x Then
  4.                     tn = treeListView1.Nodes(i)
  5.                     tn.Selected = True
  6.                     treeListView1.RowSelectColor = Color.Red
  7.                     Dim item As TreeListNode
  8.                     item = tn
  9.                     Dim scroll As Integer
  10.                     scroll = item.RowNumber(True)
  11.                     If item.Selected Then
  12.                         treeListView1.scrolltorow(scroll)
  13.                     End If
Once I got the row number(scroll) I passed that to my componenet class as row
20 is the value of each click of the vscrollbar in the treelistview. so my row number * 20 - 20 will take the selected item that was found and make the scrollbar scroll down until the selected item is the top item...here is the code...
Expand|Select|Wrap|Line Numbers
  1. Public Class ScrollTree
  2.     Inherits TreeListView
  3.     Sub scrolltorow(ByVal row As Integer)
  4.         VScrollBar.Value = row * 20 - 20
  5.     End Sub
Well thanks for all the help
Nov 7 '07 #6
Plater
7,872 Expert 4TB
Is this a web application by any chance? That might explain why what I said didn't work.
Nov 7 '07 #7
KA NMC
40
Is this a web application by any chance? That might explain why what I said didn't work.

No its not a web application...I believe what you said didnt work is because - I'm using a custom control tree/listview created in c# - which was nothing but trouble(full of bugs) but hacking away at it I was able to get rid of some of the bugs ...except for the ensurevisible one - but using the inherit worked like a charm.

Any way I got another question? I got different application which is working beautifully until I noticed one little-big thing. Basically I have a master/detail datagrid. I want the grid to update a record on cell value change. As of right now it is updating on text value change as the user go from record to record - I did this so that I can have a working application just to figure it out this update issue. When you look at the Database and view the last mod by it is getting hits when nothing changes. Any ideas?
Nov 9 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Benny Raymond | last post by:
I've looked around msdn for about an hour now and can't figure out how to place an event when the user scrolls, or even how to get the value of where the scroll bar is actually placed... Anyone...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
0
by: alcurb | last post by:
I have a ListView control populated with 30 items. ListView height only allows you to see 20 rows at a time. I want to drag an item to the bottom of the list (to the last row), but ListView...
1
by: Christof Nordiek | last post by:
Hi, in my app i use a treeview. If the treeview isn't large enough to show all items it automoatically gets a vertical scrollbar. But i can't always scroll to the last item. Sometimes the last...
6
by: Mike Johnson | last post by:
I have a ListView on a form, I'm displaying the items as a list. The Scroll is set to true. I want to know how can I set the scroll bar to Vertical?
6
by: Brad Pears | last post by:
As part of my vb.net 2005 application I would like to automatically select the very first item (index 0) in a listview containing menu items. That way the the listviews "afterselect" event would...
2
by: Rich Raffenetti | last post by:
In the listview control I can set the highlighted item with listview.focus() listview.items(integerValue).selected=true How do I programmatically scroll the pane of the details view to bring...
5
by: Lord Zoltar | last post by:
Hello, I'm trying to force a listView to scroll to some location when a certain button is clicked on. I've found that the SendMessage function seems to be the choice way of doing it. Here's what...
3
by: uday1302 | last post by:
Hi All, I have tried by seeing an example. See the below code. Here I have a Problem. Treeview has already one root node and twochild nodes with it. They have to be dragged and dropped in listview....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.