473,394 Members | 1,770 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,394 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 7125
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.