473,395 Members | 2,796 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,395 software developers and data experts.

Listbox: scroll to the selected item by code.

Dear All,

I have code that selects - find and select - 1 item in a large listbox. This
works Ok but most of the time the selected item isn't visible without
scrolling down manualy. Is this possible by code?

Filip
Nov 12 '05 #1
4 42658
2 thoughts.
1) Use a combo box where as you type the letters you get closer to the entry
you are lookin for
2) Use a list box, but have an option grid of letters and numbers to
select the initial letter say and ensure that the query for the list box has
a "WHERE WhatImSearchingFor Like Like [screen].[activeform]![Filter].

If for example you press the letter "F", the filter will look "[" &
Screen.ActiveForm!ShowFilter & "]*" where there is anothe control on the
form Screen.ActiveForm!ShowFilter which stores the F

Phil
"Filips Benoit" <be***********@pandora.be> wrote in message
news:yT********************@phobos.telenet-ops.be...
Dear All,

I have code that selects - find and select - 1 item in a large listbox. This works Ok but most of the time the selected item isn't visible without
scrolling down manualy. Is this possible by code?

Filip

Nov 12 '05 #2
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.
"Filips Benoit" <be***********@pandora.be> wrote in message
news:yT********************@phobos.telenet-ops.be...
Dear All,

I have code that selects - find and select - 1 item in a large listbox. This works Ok but most of the time the selected item isn't visible without
scrolling down manualy. Is this possible by code?

Filip


Nov 12 '05 #3
"Filips Benoit" <be***********@pandora.be> wrote in message news:<yT********************@phobos.telenet-ops.be>...
Dear All,

I have code that selects - find and select - 1 item in a large listbox. This
works Ok but most of the time the selected item isn't visible without
scrolling down manualy. Is this possible by code?

Filip


If you don't need to use the MultiSelect property of the listbox,
wouldn't this be easier with a combobox with the LimitToList property
set to true? Then you could do something like set the controlsource
for the combobox after the user has entered a character (to limit the
number of records displayed initially).
Nov 12 '05 #4
THANKX³,

Thats just what I was looking for.

Filip
"Stephen Lebans" <Fo****************************************@linval id.com>
wrote in message news:Vk********************@ursa-nb00s0.nbnet.nb.ca...
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.
"Filips Benoit" <be***********@pandora.be> wrote in message
news:yT********************@phobos.telenet-ops.be...
Dear All,

I have code that selects - find and select - 1 item in a large

listbox. This
works Ok but most of the time the selected item isn't visible without
scrolling down manualy. Is this possible by code?

Filip

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Irene | last post by:
I'm developing a Web application where a user selects from a listbox which can have many items. The initial display only shows about 10 items. After a postback, the listbox is automatically...
6
by: Adam Klobukowski | last post by:
Hello. /windows forms/ I'm marking listbox items as selected, and I'd like to scroll listbox to a selected entry if it is off-screen. How can I do it? -- Semper Fidelis Adam Klobukowski
9
by: Larry Serflaten | last post by:
I'm drawing my own inherited listbox, and I don't want the user to select any items, but I do want to allow them to scroll the listbox. When they click on an item, there is a flicker of the...
2
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
2
by: Hitesh | last post by:
I have a listbox and the values get selected (highlighted) from code. I can highlight the corresponding list box items, but they do not show in the listbox I have to scroll through the list box to...
3
by: superjacent | last post by:
Hope someone can help. I have a listbox displaying time periods in blocks of 15 mins for a 24 hour period, all up 96 rows. The listbox can only visibly show 20 rows a time. The default...
0
by: R.Nijkamp | last post by:
Hello, i was wondering if its an limitation of IE when a asp.net listbox is set disabled, then a user wont be able to scroll inside the listbox. While the user can scroll inside the listbox when...
0
by: scartin | last post by:
Hi, I have a multi-select ListBox that shows 5 rows at a time, but contains possibly a hundred or more items. As I retrieve relevant data from the database, I set the SelectedIndex of the rows...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...
0
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,...

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.