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

How to make first selected item in a list box visible

I've tried googling for the answer to this problem, without any luck.
I'm sure the truth must be out there somewhere!

I have a multiselect listbox populated with many items (set by the
RowSource property). In my code I cause a number of these to be
selected - but if the first selected item is not within the currently
visible range then there is no change to the display. This gives the
impression that nothing has happened.

I think that for a single select box the display moves automatically
to include the selected item. How can I arrange for something
comparable to occur with an extended multiselect listbox?

Thanks in advance

Peter

Mar 22 '07 #1
3 6269
pe**********@talk21.com wrote:
I've tried googling for the answer to this problem, without any luck.
I'm sure the truth must be out there somewhere!

I have a multiselect listbox populated with many items (set by the
RowSource property). In my code I cause a number of these to be
selected - but if the first selected item is not within the currently
visible range then there is no change to the display. This gives the
impression that nothing has happened.

I think that for a single select box the display moves automatically
to include the selected item. How can I arrange for something
comparable to occur with an extended multiselect listbox?

Thanks in advance

Peter
Take off wordwrap if link wraps. I think it will point you to a solution.
http://groups.google.com/group/micro...47aabc70050e8f
Mar 22 '07 #2
Thank you for those hints. Looking through the code, I found that
the .ListIndex method does seem to move the display to accommodate the
selection, while the .Selected(i)=True method does not. The trouble
is that the .ListIndex method also overwrites previous selections,
which is a problem on a multiselect list.

My solution was to use a flag initially set to false. Then if the
flag is false, set the selection using .ListIndex and change the flag
to true, else use .Selected(i)=True. I also iintroduced an initial
dummy selection of the last index item which moved the display to the
end of the list. When this was overwritten by the first selection,
the display moved up such that the first selected item was at the top
of the list.

My code is given below. This code sits within a larger loop in which
successive values of 'a' are read from a file, and if they match an
item in the listbox lstOffenceCodes then that item is selected. The
flag OffenceCodeFlag is initially cleared.
lstOffenceCodes.SetFocus
For i = 0 To lstOffenceCodes.ListCount - 1
If lstOffenceCodes.ItemData(i) = a Then
If Not OffenceCodeFlag Then
' If first selection from listbox then
' Make a dummy selection of the last
listbox item
' This will cause the display to move to
the end of the list
lstOffenceCodes.ListIndex =
lstOffenceCodes.ListCount - 1
' Now make the actual selection. This will
overwrite the
' dummy selection, and ensure the selected
item appears
' towards the top of the list box
lstOffenceCodes.ListIndex = i
' Set the flag so future selections do not
disturb the display
OffenceCodeFlag = True
Else
' If not the first selection from listbox
then
' Make selection via the .Selected property
' This does not cause the display to change
lstOffenceCodes.Selected(i) = True
End If
End If
Next i

Mar 23 '07 #3
I haven't tried this but what happens if you go through the list
backwards so the last item selected is at the top?

Mar 23 '07 #4

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

Similar topics

1
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i...
3
by: Stanley J Mroczek | last post by:
I have tried this with no luck. What i want is to show the selected item on the first post. the selected item is NY but the first in the list shows as selected. If Page.IsPostBack = False Then...
3
by: Siamak Zahedi | last post by:
Hi, weird problem I'm having cant seem to figure out what is going on. I have a dropdownlist that gets populated from db and a button that causes a post back when I assign the value of the...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
3
by: xianxian | last post by:
Hi guys, I'm having trouble getting my Datagrid to display according to Checkboxes checked values. On my Checkboxes, I have 5 values :- 1) Apartment/Condo 2) Executive Condo 3) Detached 4)...
2
by: Jake Barnes | last post by:
Imagine I've this block of HTML: <p>Alex Schein Mailing List <input type="checkbox" name="newslettersToUse" value="133156"> (<a href="mcControlPanel.php"...
2
by: Eniac | last post by:
*argh* ... *pull hairs* I've recently started developing from ASP to ASP.NET The switch was fairly smooth since i had done some VB.net before ... then came...FORMS! :) I find it astounding...
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...
6
by: probashi | last post by:
Hi, Issue: After post back selected item of a list box is getting out of focus (when it contains more items than it's size). I have a List Box in an ASPX page. I select an item from the...
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.