473,787 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the last selected item in multiselect ListBox?

Anyone knows if there is some kind of property or function that will
return the last selected/deselected item/index in a multiselect
ListBox? SelectedIndex will point to first index in the
SelectedIndices collection, so this is a dead end. My solution so far
is to override the mouse click and key pressed events. However, since
arrow up/down seems to keep a record of the item that currently has
focus somehow, I would believe this information is stored somewhere.
Any help is appreciated since I can't seem to figure this out without
tending to overkill solutions.

- Peder -
Nov 16 '05 #1
2 7958
A quick thought -- if we can query the control to get the value of the
number of items in the ListBox we can get the value of the last item
in its collection. That should be in the documentation.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee. com
URL http://www.metromilwaukee.com/clintongallagher/

"Peder Y" <py*****@ec.auc kland.ac.nz> wrote in message
news:10******** *************** ***@posting.goo gle.com...
Anyone knows if there is some kind of property or function that will
return the last selected/deselected item/index in a multiselect
ListBox? SelectedIndex will point to first index in the
SelectedIndices collection, so this is a dead end. My solution so far
is to override the mouse click and key pressed events. However, since
arrow up/down seems to keep a record of the item that currently has
focus somehow, I would believe this information is stored somewhere.
Any help is appreciated since I can't seem to figure this out without
tending to overkill solutions.

- Peder -

Nov 16 '05 #2
Sure, but a _collection_ doesn't support that property. Items.Count
gets the number of items. I've looked high and low for an answer to
this question, and it doesn't seem to be answered anywhere. And "last
item" can be a bit obscure. There is a subcollection called
SelectedItems/Indices, but the item with focus does not necessarily
have to be in this collection. For example one can select a range of
items, then deselect one of them. The deselected one will have focus,
but won't be selected.

This is a tough nut!

- Peder -
"clintonG" <csgallagher@RE ************@me tromilwaukee.co m> wrote in message news:<uE******* ******@TK2MSFTN GP11.phx.gbl>.. .
A quick thought -- if we can query the control to get the value of the
number of items in the ListBox we can get the value of the last item
in its collection. That should be in the documentation.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee. com
URL http://www.metromilwaukee.com/clintongallagher/

"Peder Y" <py*****@ec.auc kland.ac.nz> wrote in message
news:10******** *************** ***@posting.goo gle.com...
Anyone knows if there is some kind of property or function that will
return the last selected/deselected item/index in a multiselect
ListBox? SelectedIndex will point to first index in the
SelectedIndices collection, so this is a dead end. My solution so far
is to override the mouse click and key pressed events. However, since
arrow up/down seems to keep a record of the item that currently has
focus somehow, I would believe this information is stored somewhere.
Any help is appreciated since I can't seem to figure this out without
tending to overkill solutions.

- Peder -

Nov 16 '05 #3

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

Similar topics

4
42760
by: Filips Benoit | last post by:
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
1
1616
by: Sally | last post by:
In a simple multiselect listbox, what is the code for the AfterUpdate event to determine if the item clicked on was selected or deselected? Thanks! Sally
5
3861
by: Silvia | last post by:
Hi I have a listbox in a form which has been set on multiselect simple. If I select some of the items on the list on day1, save and exit, and return on day2, the items I selected on day1 do not remain highlighted. How do I ensure that when I return to the form on day2, that the items I selected on day1 are still highlighted? Thanks, Silvia
1
7902
by: jez123456 | last post by:
Hi, I have a windows form with a listbox control. My code all works correctly when deleting an item from the listbox except the last item. I get the following message when trying to delete the last item:- Specified argument was out of the range of valid values. Parameter name: '64' is not a valid value for 'Value'. The 64 reduces depending on how many listbox items are displayed.
0
1440
by: antonyliu2002 | last post by:
I am not new to programming, but I am new to VB .NET. I have a multiselect listbox like this: Please select your favorite fruit: Apple Banana Coconut Date
5
2435
by: John Veldthuis | last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox. Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is the last entry and you select another index it goes boom!!!. Funny thing is the SelectedIndex Changed routine fires off perfectly and then crash after the return from this code. Now looking around the news groups it appears to be a bug in the .net...
1
1134
by: Bruce F | last post by:
I have a multiselect ListBox and I want to determine which items are selected. I don't want to use "SelectedItems" but want to loop through all items and check if selected or not. What I want is: For i = 0 To ListBox1.Items.Count ' code to check if item(i) is selected Next
1
1459
by: BillAtWork | last post by:
Hi, I have a listbox (in a user control) which has items add/removed via javascript (i.e. an "add item" link which uses a popup selection screen to add items and a "remove item" link which deletes any selected row(s)). There is a strange problem that when I inspect the list of items during a postback the list appears to be empty (even though I added items). I noticed that when I multiselect one or more items, only those selected items...
3
6303
by: peter.mosley | last post by:
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...
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9497
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,...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
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
7517
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
6749
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();...
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
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.