By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,456 Members | 1,529 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,456 IT Pros & Developers. It's quick & easy.

Listbox Issue. Scroll two listboxes at same time.

P: 23
Hi to all
I have two listbox with lots of items in it. I want to do is, when user scroll one listbox then second listbox automatically scroll according to first. Someone knows how to do this. I search the web but didn’t get what I really need. Help Me!
Thanx in Advance
May 11 '10 #1

✓ answered by ADezii

@SandeepJagdeva
In the absolute simplest of cases where both List Boxes contain the same number of entries, the 1st List Box is named List1, and the 2nd List Box is named List2, the following code, when placed in the AfterUpdate() Event of List 1, will keep the scrolled items of List 2 in sync with List 1 when using the UP and DOWN Arrow Keys:
Expand|Select|Wrap|Line Numbers
  1. Private Sub List1_AfterUpdate()
  2. Dim L1 As ListBox
  3. Dim L2 As ListBox
  4.  
  5. Set L1 = Me![List1]
  6. Set L2 = Me![List2]
  7.  
  8. L2.Selected(L1.ListIndex) = True
  9. End Sub
P.S. - I will not get more complicated than this since, like linq and Delerna, I would like to know also what you are trying to accomplish.

Share this Question
Share on Google+
6 Replies


Delerna
Expert 100+
P: 1,134
You need an event that occurs when the listbox scrolls.
You also need a read/write property that identifies the index of the item at the top of the list in view.
As far as I can see, in access, neither of these exist for the list box.

Maybe it's time to rethink what you are doing?
I can't imagine the scenario where you would need to do that
which wouldn't be better achieved some other way.


Microsoft does have an example of doing this
but it is done in visual basic...not VBA

google this
How to Program Two List Boxes to Scroll Together
May 11 '10 #2

missinglinq
Expert 2.5K+
P: 3,532
I'd really like to know the point of this requirement. Like Delerna, I can't imagine the scenario where you would need to do that which wouldn't be better achieved some other way.

Linq ;0)>
May 12 '10 #3

ADezii
Expert 5K+
P: 8,597
@SandeepJagdeva
In the absolute simplest of cases where both List Boxes contain the same number of entries, the 1st List Box is named List1, and the 2nd List Box is named List2, the following code, when placed in the AfterUpdate() Event of List 1, will keep the scrolled items of List 2 in sync with List 1 when using the UP and DOWN Arrow Keys:
Expand|Select|Wrap|Line Numbers
  1. Private Sub List1_AfterUpdate()
  2. Dim L1 As ListBox
  3. Dim L2 As ListBox
  4.  
  5. Set L1 = Me![List1]
  6. Set L2 = Me![List2]
  7.  
  8. L2.Selected(L1.ListIndex) = True
  9. End Sub
P.S. - I will not get more complicated than this since, like linq and Delerna, I would like to know also what you are trying to accomplish.
May 12 '10 #4

P: 23
First of all Thanx to all for give me some good idias.
I gave u some detail why I need to scroll both listbox at same time. I have a form that prints Daily billing of a ‘Departmental Store’. I add two listbox name “lst_SrNo” is single column and “lstProduct_detail” with 5 column, one is for Serial No and second is for Product detail , a combobox, and some textbox for complete the task. Now user selects a product code from combobox that is connected to a table named ‘product_detail’ and detail of selected code will be loaded to lstProduct_detail, and in the lst_SrNo a number is added to it. As user select product code, then first listbox add a number like lstNumber=lstNumber+1. Product detail adds to Second listbox. Its ok till now, if user add more then 16 items in listbox then both list box need to scroll down, if user scroll “lstProduct_detail” listbox then its corresponding Serial No. does’t match. is it clear

Why I need two list box?
Ans is in my previous post :
http://bytes.com/topic/access/answer...-listbox-value
May 12 '10 #5

P: 23
@ADezii
Thanx man
This is what i need. This will sloved my problem, is any way, that this will wrok with mouse as with key up-down, when user click on scroll button of listbox?
May 12 '10 #6

ADezii
Expert 5K+
P: 8,597
@SandeepJagdeva
To the best of my knowledge, this simply cannot be done.
May 12 '10 #7

Post your reply

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