If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Vertical Scroll Bar in ListBox
Hello,
I want to know how to set the Vertical Scroll Bar to certain positions in a List Box through code. Any help would be greatly appreciated. Thank you, Jeff |
#2
|
|||
|
|||
On Wed, 22 Sep 2004 09:29:31 -0700,
wrote: Hello, I want to know how to set the Vertical Scroll Bar to certain positions in a List Box through code. Any help would be greatly appreciated. Thank you, Jeff It's not the scroll bars that move, it's the row that you select that moves the scroll bars. Me!ListBox.selected(x) =true Where x is whatever row you wish to select. To always show the last row: Me!ListBox.Selected(ListBox.ListCount - 1) = True Where you place the code depends upon what you are doing. End Sub -- Fred Please only reply to this newsgroup. I do not reply to personal email. |
#3
|
|||
|
|||
That works in a regular list box, but what about a list box in "Multi-list"
mode? When I use code to select a row, the row gets selected, but the records are not adjusted to show it to the user. Craig "fredg" wrote: On Wed, 22 Sep 2004 09:29:31 -0700, wrote: Hello, I want to know how to set the Vertical Scroll Bar to certain positions in a List Box through code. Any help would be greatly appreciated. Thank you, Jeff It's not the scroll bars that move, it's the row that you select that moves the scroll bars. Me!ListBox.selected(x) =true Where x is whatever row you wish to select. To always show the last row: Me!ListBox.Selected(ListBox.ListCount - 1) = True Where you place the code depends upon what you are doing. End Sub -- Fred Please only reply to this newsgroup. I do not reply to personal email. |
#4
|
|||
|
|||
See:
http://www.lebans.com/List_Combo.htm#ScrollListbox Scroll a ListBox to a specific row. Emulates the VB ListBox TopIndex property. You can alter the code to easily have the selected row display as the first or last row as well. The example code is placed behind a Command Button. ' *** CODE START Private Sub cmdListIndex_Click() On Error GoTo Err_cmdListIndex_Click ' Always make NumRows an odd number ' if you want selected Row to be in the ' middle of the ListBox. ' NumRows is the number of completely visible rows in the ListBox Const NumRows = 7 ' Row we want displayed in middle of ListBox. Dim intDesiredRow As Integer ' Arbitrarily select the 24th row. intDesiredRow = 24 ' ListBox must have the Focus Me.List2.SetFocus ' Force ListBox to start from the top Me.List2.ListIndex = 1 ' Force the Scroll offset we desire Me.List2.ListIndex = intDesiredRow + (NumRows / 2) ' Now select the row without further scrolling Me.List2.ListIndex = intDesiredRow Exit_cmdListIndex_Click: Exit Sub Err_cmdListIndex_Click: MsgBox Err.Description Resume Exit_cmdListIndex_Click End Sub ' ***CODE END -- HTH Stephen Lebans http://www.lebans.com Access Code, Tips and Tricks Please respond only to the newsgroups so everyone can benefit. "Craig" wrote in message ... That works in a regular list box, but what about a list box in "Multi-list" mode? When I use code to select a row, the row gets selected, but the records are not adjusted to show it to the user. Craig "fredg" wrote: On Wed, 22 Sep 2004 09:29:31 -0700, wrote: Hello, I want to know how to set the Vertical Scroll Bar to certain positions in a List Box through code. Any help would be greatly appreciated. Thank you, Jeff It's not the scroll bars that move, it's the row that you select that moves the scroll bars. Me!ListBox.selected(x) =true Where x is whatever row you wish to select. To always show the last row: Me!ListBox.Selected(ListBox.ListCount - 1) = True Where you place the code depends upon what you are doing. End Sub -- Fred Please only reply to this newsgroup. I do not reply to personal email. |
#5
|
|||
|
|||
Thanks Stephen! That looks like it is exactly what I need. I'll go play
with that code now. Thanks! Craig "Stephen Lebans" wrote: See: http://www.lebans.com/List_Combo.htm#ScrollListbox Scroll a ListBox to a specific row. Emulates the VB ListBox TopIndex property. You can alter the code to easily have the selected row display as the first or last row as well. The example code is placed behind a Command Button. ' *** CODE START Private Sub cmdListIndex_Click() On Error GoTo Err_cmdListIndex_Click ' Always make NumRows an odd number ' if you want selected Row to be in the ' middle of the ListBox. ' NumRows is the number of completely visible rows in the ListBox Const NumRows = 7 ' Row we want displayed in middle of ListBox. Dim intDesiredRow As Integer ' Arbitrarily select the 24th row. intDesiredRow = 24 ' ListBox must have the Focus Me.List2.SetFocus ' Force ListBox to start from the top Me.List2.ListIndex = 1 ' Force the Scroll offset we desire Me.List2.ListIndex = intDesiredRow + (NumRows / 2) ' Now select the row without further scrolling Me.List2.ListIndex = intDesiredRow Exit_cmdListIndex_Click: Exit Sub Err_cmdListIndex_Click: MsgBox Err.Description Resume Exit_cmdListIndex_Click End Sub ' ***CODE END -- HTH Stephen Lebans http://www.lebans.com Access Code, Tips and Tricks Please respond only to the newsgroups so everyone can benefit. "Craig" wrote in message ... That works in a regular list box, but what about a list box in "Multi-list" mode? When I use code to select a row, the row gets selected, but the records are not adjusted to show it to the user. Craig "fredg" wrote: On Wed, 22 Sep 2004 09:29:31 -0700, wrote: Hello, I want to know how to set the Vertical Scroll Bar to certain positions in a List Box through code. Any help would be greatly appreciated. Thank you, Jeff It's not the scroll bars that move, it's the row that you select that moves the scroll bars. Me!ListBox.selected(x) =true Where x is whatever row you wish to select. To always show the last row: Me!ListBox.Selected(ListBox.ListCount - 1) = True Where you place the code depends upon what you are doing. End Sub -- Fred Please only reply to this newsgroup. I do not reply to personal email. |
#6
|
|||
|
|||
wrote in news:013f01c4a0c1$56b12a00
: Hello, I want to know how to set the Vertical Scroll Bar to certain positions in a List Box through code. Any help would be greatly appreciated. Thank you, Jeff I wanted to show a simple way to reset the scroll bar back to the top and show the first item of the listbox: Me!List2 = Me!List2.ItemData(0) Me!List2 = Null What this code does is set the value of the listbox to the very first line which causes the listbox to scroll up to the top. Then you set the value to null to clear out any selection. All this is done without changing the focus on the form! (important for my application) I was using the selection in one listbox to set the rowsource of a second listbox. I did not want the focus to be taken away from the first listbox because the item that was selected in the first listbox would not be indicated. It was driving me crazy trying to figure out how to reset the second listbox without changing the focus. Every time the user was selecting a new value in the first listbox the second listbox would stay selected to the last value that was picked, and sometimes it would be scrolled way down near the bottom of the list, which was confusing for my users. This method seemed to solve my problem. I hope that this tip saves people from the frustration I experienced. -Wapeka |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
RowSourceType Property(User-Defined Function)...Help | Roddy | General Discussion | 1 | September 3rd, 2004 02:00 PM |
Add Item from one listbox to the next | alex pLEASE HELP | General Discussion | 0 | July 22nd, 2004 08:53 PM |
MS Mouse - Wheel does not scroll in VBA | Andre Uys | General Discussion | 4 | July 22nd, 2004 06:23 AM |
Excel Chart Vertical Lines Corrupting? | Ken Black | Charts and Charting | 4 | June 4th, 2004 09:16 PM |
Vertical Scroll Bar Page Names | Heather | Page Layout | 1 | May 13th, 2004 03:56 AM |