-
May 26th, 2023, 09:42 PM
#1
Thread Starter
New Member
VB 2008 Display Specified Value in the Centre (vertically) of a List Box on Opening
Hi all,
I pre-populate a list box with values using a Do Until loop that represent altitudes for an aircraft one thousand feet apart vertically - in this case from 100, 110,...400, 410, 420, 430 (43,000ft). When the list box opens, the top of the range (430) is displayed at the top of the list. However, I want the last selected value from the list (representing the level that the aircraft has currently been cleared to fly at) to appear in the middle of the range of values when the list box is opened by the user the next time. I have 9 values displayed in the list, so, for example, the last value selected was 330, so when the list box opens, I want 330 displayed in the middle of the range of values, with 370 at the top and 290 at the bottom. I have searched a number of forums but have not seen anything that covers this issue. Thanks for any help that can offered.
-
May 26th, 2023, 10:06 PM
#2
Re: VB 2008 Display Specified Value in the Centre (vertically) of a List Box on Openi
Read up on the TopIndex property of ListBox. That lets you set the index that is visible at the top of the ListBox, which by extension allows you to control which item is in the "middle" of the ListBox. Of course you'll have to do some simple math to calculate which index to make the "top" if all you have is the index that you want in the middle.
https://learn.microsoft.com/en-us/do...owsdesktop-7.0
Good luck.
-
May 27th, 2023, 02:47 AM
#3
Thread Starter
New Member
Re: VB 2008 Display Specified Value in the Centre (vertically) of a List Box on Openi
Originally Posted by OptionBase1
Read up on the TopIndex property of ListBox. That lets you set the index that is visible at the top of the ListBox, which by extension allows you to control which item is in the "middle" of the ListBox. Of course you'll have to do some simple math to calculate which index to make the "top" if all you have is the index that you want in the middle.
https://learn.microsoft.com/en-us/do...owsdesktop-7.0
Good luck.
Excellent. I will have a look at the material. Thanks very much!
-
May 28th, 2023, 05:54 PM
#4
Thread Starter
New Member
Re: VB 2008 Display Specified Value in the Centre (vertically) of a List Box on Openi
Originally Posted by OptionBase1
Read up on the TopIndex property of ListBox. That lets you set the index that is visible at the top of the ListBox, which by extension allows you to control which item is in the "middle" of the ListBox. Of course you'll have to do some simple math to calculate which index to make the "top" if all you have is the index that you want in the middle.
https://learn.microsoft.com/en-us/do...owsdesktop-7.0
Good luck.
Thanks OptionBase1. I didn't know that the TopIndex property existed, and after the mental gymnastics that I had been contemplating with index values, I am amazed that the solution was so simple. I set the initial displayed range with a hard-coded value and then it is just a case of TopIndex = SelectedIndex - 4. Brilliant!!
-
May 29th, 2023, 06:33 AM
#5
Re: VB 2008 Display Specified Value in the Centre (vertically) of a List Box on Openi
Originally Posted by cjr23
I didn't know that the TopIndex property existed
This is why you should ALWAYS read the documentation. Whenever you're using a new type or member, read the documentation first and you may just learn something new that you wouldn't have even known to look for. In the case of new types, you can see what members it has and, even if you don't need them now, you'll know they are there if you do need them in future. You can go straight to the topic for a type or member using context-sensitive Help (F1) or use the Help menu to go to the home page.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|