473,786 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6302
pe**********@ta lk21.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)=Tr ue 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)=Tr ue. 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
4333
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 want to make first text as Table Heading/menu category. For examle in the given menu i want to make a heading as "Comp. Languages" which won't be a link. 2) The position of this menu is absolute to the page. I want to make it absolute to the Table...
3
1790
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 Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim myCommand As SqlCommand = New SqlCommand("Get_States",
3
4202
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 dropdownlist to a string var it always returns the first item regardless of what was selected code is simple
5
13394
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 to get a Boolean value TRUE or FALSE when a checkBox is selected. When the checkBoxList was out of the DataList i used "OnSelectedIndexChanged" and it was returning what i wanted but if its in a
3
1591
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) Semi-detached
2
9068
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" onClick="hideOrShowDivById('emailList133156'); return false;">See emails?</a>)</p> <form method="post" action="mcControlPanel.php" id="emailList133156" style="display:none;"><textarea name="formInputs">nazjeehaj@son.org,
2
2287
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 at how difficult it has become to control a form, something that was so dead easy in ASP.
2
4090
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 find them. How can I setFocus on the highlighted data items in the listbox after they are highlighted. The selection mode is set to multiple for the listbox -- Thanks
6
16417
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 ListBox and after post back the item is still selected but it is not focused (i.e. I have to scroll down to see the selected item) Any way to fix this!
0
9491
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.