473,857 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remember position of scrolling in listview in VB6

Robbie
180 New Member
Hi again, I have a listview which gets cleared and has items added again every now and then, and it's very annoying to use because once it's cleared, the scrollbar goes back to the top.
I'd like it to go back to where it was before, as if it's not obvious anything ever happened.

I know there's a similar topic around, but that's in VB.NET which I'm not at all familiar with.

So far I have been able to make it remember what the last selected item was and re-select this same item afterwards, but this does not make the listview scroll back down to that position (if you scroll down, you can see that same item's selected again though). I used this code:
Expand|Select|Wrap|Line Numbers
  1. 'Make a note of selected item
  2.     On Error Resume Next
  3.         OrigListPosition = MainList.SelectedItem.Index
  4.     If Err.Number = 91 Then OrigListPosition = -1
  5.     On Error GoTo 0
  6.     'All done, error-checking's back on, and if no item was selected (error 91 here),
  7.     'OrigListPosition is -1, otherwise it's the index.
  8.  
  9. '<LIST-UPDATING CODE>
  10.  
  11. 'Make the item which was selected before re-making this list, be selected again
  12.     If OrigListPosition > -1 And OrigListPosition < MainList.ListItems.Count Then
  13.     'Checks to make sure it's less than how many items there are, because this time the list
  14.     'may have less items.
  15.         MainList.ListItems(OrigListPosition).Selected = True
  16.     End If
Apr 12 '07 #1
6 11175
iburyak
1,017 Recognized Expert Top Contributor
You probably can save ListIndex in a variable and then after reload set it back to a ListIndex which is basically you are moving to whatever was previously selected.

I didn't test it thou it is just an idea.
Apr 12 '07 #2
Robbie
180 New Member
You probably can save ListIndex in a variable and then after reload set it back to a ListIndex which is basically you are moving to whatever was previously selected.

I didn't test it thou it is just an idea.
Good idea, but a ListView does not have a ListIndex, and even if it did I think it is read-only... =/

It has SelectedItem.In dex but unfortunately that is read-only.
Apr 12 '07 #3
Robbie
180 New Member
Sorry for a double-post but at least it has some useful info.

I thought of a way to do it:
- Event triggers updating list (e.g. typing in a text box).
- Make note of selected item.
- Update list.
- Select previously-selected item.
- Bring focus to the ListView.
- Use SendKeys() to simulate Up arrow then Down arrow to force VB to realize the selection is at that position, then it would scroll to that position (it does this if you press Up then Down yourself).
- Give focus back to the textbox which you first typed in.

I thought that was all going to work fine, BUT it seems you can't use SetFocus on a ListView! If I do MainList.SetFoc us (SetFocus shows up in the little menu of Properties/Methods when you type the dot after MainList), then when I run it I get runtime error 5, invalid procedure call or argument! ><
aaagh...
Apr 12 '07 #4
iburyak
1,017 Recognized Expert Top Contributor
OK Sorry I was lazy thought it is simple. But look at my working solution.

Put a ListView and a button on your form and copy code.....

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. For i = 0 To 1000
  3.     ListView1.ListItems.Add , , "Irina " & i
  4. Next
  5.  
  6.  
  7. End Sub
  8.  
  9.  
  10. Private Sub Command1_Click()
  11. Dim a
  12. a = ListView1.GetFirstVisible.Index
  13.  
  14.  
  15. For i = 1000 To 1 Step -1
  16.     ListView1.ListItems.Remove i
  17. Next
  18.  
  19. DoEvents
  20. For i = 0 To 1000
  21.     ListView1.ListItems.Add , , "Irina " & i
  22. Next
  23. DoEvents
  24. ListView1.ListItems.Item(a).EnsureVisible
  25. End Sub

Good Luck
Irina.
Apr 13 '07 #5
Esmael
58 New Member
Hi....

Are you familiar with ARRAYS... i think this can solve your problem....
A dynamic arrays can solve your problem... and since your adding and adding an entry Use Redim for your array... i hope you get my idea...


One more thing i dont regularly visit this site because am usually bz....


GoodLuck....


Sorry for a double-post but at least it has some useful info.

I thought of a way to do it:
- Event triggers updating list (e.g. typing in a text box).
- Make note of selected item.
- Update list.
- Select previously-selected item.
- Bring focus to the ListView.
- Use SendKeys() to simulate Up arrow then Down arrow to force VB to realize the selection is at that position, then it would scroll to that position (it does this if you press Up then Down yourself).
- Give focus back to the textbox which you first typed in.

I thought that was all going to work fine, BUT it seems you can't use SetFocus on a ListView! If I do MainList.SetFoc us (SetFocus shows up in the little menu of Properties/Methods when you type the dot after MainList), then when I run it I get runtime error 5, invalid procedure call or argument! ><
aaagh...
Apr 13 '07 #6
Robbie
180 New Member
OK Sorry I was lazy thought it is simple. But look at my working solution.

Put a ListView and a button on your form and copy code.....

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. For i = 0 To 1000
  3.     ListView1.ListItems.Add , , "Irina " & i
  4. Next
  5.  
  6.  
  7. End Sub
  8.  
  9.  
  10. Private Sub Command1_Click()
  11. Dim a
  12. a = ListView1.GetFirstVisible.Index
  13.  
  14.  
  15. For i = 1000 To 1 Step -1
  16.     ListView1.ListItems.Remove i
  17. Next
  18.  
  19. DoEvents
  20. For i = 0 To 1000
  21.     ListView1.ListItems.Add , , "Irina " & i
  22. Next
  23. DoEvents
  24. ListView1.ListItems.Item(a).EnsureVisible
  25. End Sub

Good Luck
Irina.
Thanks! =D
But I needed to change GetFirstVisible .Index to SelectedItem.In dex - GetFirstVisible always gave back about 5 items past the last item in view in the list, for some reason.
Also, it is much easier and faster just to use ListItems.Clear , since I'm always refreshing the whole list.

Thanks again!

And Esmael, I use arrays every now and then, but I do not know about the ReDim statement...
Apr 13 '07 #7

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

Similar topics

15
3927
by: Wiktor Zychla | last post by:
today we've found a critical issue regarding the ListView from Windows.Forms. it was confirmed on several machines with Win2K and XP. here's the problem: create a ListView with about 50000 rows. now use task manager to see the GDI usage of the process. everything seems normal. now catch the ListView's scroller and start to move it downwards. you have to hold the constant speed so that the ListView is constantly repainted. look at the...
1
10636
by: SlantyOD | last post by:
Hi All, I'm trying to tie two ListViews together so that when the user scrolls one, the other stays 'in sync'. Since there are no OnScroll events, and the scroll bar position is unavailable, I've been forced to create my own ListView class and override WndProc. In this I've caught all instances of WH_VScroll and WH_HScroll, and then I can pass this info onto the second ListView by using the User32.dll method SendMessage. This all works...
0
2899
by: Tim Bücker | last post by:
Hello. Is it really not possible to hide the scrollbars of a listview ( this.listview.Scrollable = false; ) but do some scrolling anyway ( for instance: PostMessage(this.listview.Handle, WM_VSCROLL, wParam, lParam); ) I really hope someone can tell me that it is possible... .... I want to do the scrolling using a custom scrollbar at another position ....
2
4207
by: Herbert VON GRÜNENWALD | last post by:
Hi everyone ! I would like to set an ListViewItem at a special position, into a ListView. There is Bounds, but it's a propertie, that can be only get ! (i could to that in MFC with CListCtrl.SetItemPosition(...)) thanks
5
2379
by: Martin Horn | last post by:
Hi all, I want to implement a listview with editable subitems and I assume the easiest way is to overlay a textbox over the item to be edited. With this in mind I have come up with: Using fullrowselect=true in the listview Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, _
1
2320
by: stefano.troiani | last post by:
Hi, I have a left div where there the menu is, and it is quite long, longer than the web page, so it has a scroll bar. My question is, is there a way to remember the div position once clicked in one link below the screen and the page has been recharged? I would like to avoid the users to scroll that div over and over and should be nice if it presents the same position it had before clicked. Thanks a lot,
2
1878
by: Sin Jeong-hun | last post by:
I often use detail view of the ListView control to display tabular data (is there any better way?) Many real-world applications display buttons, progress bars or dropdown lists in the columns, but it seems like ListView only allows texts. I guess if I can only know the exact bounds of the columns, I could overlay other Windows controls on it making the simmilar effects. But the problem is I can't know the exact amount of change when the...
0
1725
by: Jarppi | last post by:
Hi All, Not sure how to go about this one. I've got a windows form with five ListView controls, each listing the files in a seperate folder. What I want to achieve is this: When I scroll any of the ListView controls, I'd like the other ListView controls to scroll to the same position. I've check, but cannot find a Scrolling or Scroll event on a ListView control. I thought about catching the MouseWheel event, but this will
7
3589
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR Me.cboLocation.Text = ""
0
9923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10807
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10394
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7939
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5967
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4190
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.