Hi.
Is there a way to "unselect" items in a listbox, programmatically?
Here's what I want to do (and I've been trying to to this while
debugging
the form, but I've been unsuccessful) ...
I have a form with two listboxes.
The form, also, has two option buttons in an options group: 1 button for
the first
listbox and 1 button for the otgher listbox. The idea is to select an
optionbutton to enable the associated listbox. This is working just
fine. However ...
Let's say the user selects optionbutton 1 and enables the first listbox.
Then they select a few items in the first listbox.
Then they decide (before hitting the command button to generate the
query - which is the purpose of the form) that they really want to use
the 2nd list box. So, they hit the
other option button, which will disable listbox 1 and enable listbox 2.
However, the items that were selected in listbox 1 are still
highlighted. I want to get those highlighted items unhighlighted
(unselected).
Any ideas?
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com *** 10 21798
SueB wrote in message <OI**************@news.uswest.net> : Hi.
Is there a way to "unselect" items in a listbox, programmatically? Here's what I want to do (and I've been trying to to this while debugging the form, but I've been unsuccessful) ...
I have a form with two listboxes.
The form, also, has two option buttons in an options group: 1 button for the first listbox and 1 button for the otgher listbox. The idea is to select an optionbutton to enable the associated listbox. This is working just fine. However ...
Let's say the user selects optionbutton 1 and enables the first listbox. Then they select a few items in the first listbox.
Then they decide (before hitting the command button to generate the query - which is the purpose of the form) that they really want to use the 2nd list box. So, they hit the other option button, which will disable listbox 1 and enable listbox 2. However, the items that were selected in listbox 1 are still highlighted. I want to get those highlighted items unhighlighted (unselected).
Any ideas?
Regards, SueB
*** Sent via Developersdex http://www.developersdex.com ***
For multiselect listboxes, I believe one way is to reassigning the
rowsource
me!lstList.rowsource = me!lstList.rowsource
Else I think you could loop the list, and set each item
for l = 0 to me!lstList.listcount-1
me!lstList.selected(l) = false
next l
--
Roy-Vidar
Sue -
Try this (modified appropriately to fit your code):
Private Sub btnUseList2_Click()
Dim lngLoop As Long
lst1.Enabled = False
For lngLoop = 0 To lst1.ItemsSelected.Count - 1
lst1.Selected(lst1.ItemsSelected.Item(lngLoop)) = False
Next lngLoop
lst2.Enabled = True
End Sub
This code is run when the button to enable the second list box is clicked; it
does the following:
1) Disables the first list box
2) Cycles through the items in the first list box, de-selecting any that are
selected
3) Enables the second list box
Hope this helps!
Peter
SueB wrote: Hi.
Is there a way to "unselect" items in a listbox, programmatically? Here's what I want to do (and I've been trying to to this while debugging the form, but I've been unsuccessful) ...
I have a form with two listboxes.
The form, also, has two option buttons in an options group: 1 button for the first listbox and 1 button for the otgher listbox. The idea is to select an optionbutton to enable the associated listbox. This is working just fine. However ...
Let's say the user selects optionbutton 1 and enables the first listbox. Then they select a few items in the first listbox.
Then they decide (before hitting the command button to generate the query - which is the purpose of the form) that they really want to use the 2nd list box. So, they hit the other option button, which will disable listbox 1 and enable listbox 2. However, the items that were selected in listbox 1 are still highlighted. I want to get those highlighted items unhighlighted (unselected).
Any ideas?
Regards, SueB
Roy,
Thank you for the quick reply. I'll give both methods a try and see
which works best for me.
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***
Maybe it is better if your code does take the option button into
account. What if I think again, and revert to listbox 1? I find all my
selections gone.
That said, you have to set the Selected(row) to False, for every row
that is selected.
dim item as variant
for each item in yourlistbox.itemsselected
yourlistbox.selected(item) = false
next
SueB wrote: Hi.
Is there a way to "unselect" items in a listbox, programmatically? Here's what I want to do (and I've been trying to to this while debugging the form, but I've been unsuccessful) ...
I have a form with two listboxes.
The form, also, has two option buttons in an options group: 1 button for the first listbox and 1 button for the otgher listbox. The idea is to select an optionbutton to enable the associated listbox. This is working just fine. However ...
Let's say the user selects optionbutton 1 and enables the first listbox. Then they select a few items in the first listbox.
Then they decide (before hitting the command button to generate the query - which is the purpose of the form) that they really want to use the 2nd list box. So, they hit the other option button, which will disable listbox 1 and enable listbox 2. However, the items that were selected in listbox 1 are still highlighted. I want to get those highlighted items unhighlighted (unselected).
Any ideas?
Regards, SueB
*** Sent via Developersdex http://www.developersdex.com ***
--
Bas Cost Budde, Holland http://www.heuveltop.nl/BasCB/msac_index.html
For human replies, replace the queue with a tea
I'm sending out a global THANK YOU to all who replied. Wow. There
certainly look there are few different ways to approach this. I'll go
check out all the options and see what fits. Thanks again.
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***
Just in case anybody else looks at this post...I discovered a slight
flaw with what was suggested above. When you loop through the selected
items in the list and use the itemsselected.count as the upper boundary
of the loop without saving that value initially and using the saved
value the count reduces with every loop (as you iterate through the
items). Also, the index value of the selected items changes if you loop
from 0 up to the total selected count. So ... here is what I used to
get around the problem (I loop from the last item back up to the first
item)...
Public Sub clrSelectedDates()
Dim ix As Long
Dim lngCount As Long
'Save the selected count
lngCount = Me!lstProcesseddt.ItemsSelected.Count - 1
'Loop from the end to the beginning of the selected
For ix = lngCount To 0 Step -1
Me!lstProcesseddt.Selected(Me!lstProcesseddt.Items Selected.Item(ix)) =
False
Next ix
End Sub
Regards,
SueB
*** Sent via Developersdex http://www.developersdex.com ***
Susan Bricker <sl*****@verizon.net> wrote:
: Just in case anybody else looks at this post...I discovered a slight
: flaw with what was suggested above. When you loop through the selected
: items in the list and use the itemsselected.count as the upper boundary
: of the loop without saving that value initially and using the saved
: value the count reduces with every loop (as you iterate through the
: items). Also, the index value of the selected items changes if you loop
: from 0 up to the total selected count. So ... here is what I used to
: get around the problem (I loop from the last item back up to the first
: item)...
Would looping with a 'for each' statement, where you never
need to specify the array index avoid this problem?
--thelma
: Regards,
: SueB
No, If you loop through a collection removing items from teh collection you
should always loop downwards as Susan has discovered.
Terry Kreft
Microsoft Access MVP
"Thelma Lubkin" <th****@alpha2.csd.uwm.edu> wrote in message
news:dc**********@uwm.edu... Susan Bricker <sl*****@verizon.net> wrote: : Just in case anybody else looks at this post...I discovered a slight : flaw with what was suggested above. When you loop through the selected : items in the list and use the itemsselected.count as the upper boundary : of the loop without saving that value initially and using the saved : value the count reduces with every loop (as you iterate through the : items). Also, the index value of the selected items changes if you loop : from 0 up to the total selected count. So ... here is what I used to : get around the problem (I loop from the last item back up to the first : item)...
Would looping with a 'for each' statement, where you never need to specify the array index avoid this problem? --thelma : Regards, : SueB
Or,
with yourcollection
do while .count>0
.remove 0
loop
end with
Terry Kreft wrote: No, If you loop through a collection removing items from teh collection you should always loop downwards as Susan has discovered.
Susan -
Whoops! Sorry, I missed that. My bad.
Definitely, looping backwards is the right way to do it. I do not think,
however, you have to store the initial count in a variable.
I believe Access evaluates the loop expression only once, so even though the
count is changing, the loop statement is set in its path. You can prove this
with the following code:
lngCount = 1
For lngLoop = lngCount To 5
lngCount = 5
Debug.Print lngLoop
Next lngLoop
The loop will still have 5 iterations. Even though lngCount gets changed
inside the loop, Access has already evaluated the expression and begun the
loop. So, your code could be rewritten as follows:
Public Sub clrSelectedDates()
Dim ix As Long
'Loop from the end to the beginning of the selected
For ix = (Me!lstProcesseddt.ItemsSelected.Count - 1) To 0 Step -1
Me!lstProcesseddt.Selected(Me!lstProcesseddt.Items Selected.Item(ix))
= False
Next ix
End Sub
Note that if you were using a DO WHILE or DO...UNTIL loop, the expression
would get evaluated every time, but FOR...NEXT loops are only evaluated once.
Peter Schroeder
Susan Bricker wrote: Just in case anybody else looks at this post...I discovered a slight flaw with what was suggested above. When you loop through the selected items in the list and use the itemsselected.count as the upper boundary of the loop without saving that value initially and using the saved value the count reduces with every loop (as you iterate through the items). Also, the index value of the selected items changes if you loop from 0 up to the total selected count. So ... here is what I used to get around the problem (I loop from the last item back up to the first item)...
Public Sub clrSelectedDates()
Dim ix As Long Dim lngCount As Long
'Save the selected count lngCount = Me!lstProcesseddt.ItemsSelected.Count - 1
'Loop from the end to the beginning of the selected For ix = lngCount To 0 Step -1
Me!lstProcesseddt.Selected(Me!lstProcesseddt.Item sSelected.Item(ix)) = False Next ix
End Sub
Regards, SueB
--
Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/200507/1 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marc |
last post by:
Hi all,
I can't figure this out. I want the ability to delete an item in a
listbox and leave the window area blank, like it is when the listbox
is first created and nothing selected.
Right...
|
by: darren |
last post by:
How, using asp.net (vb.net), can I remove multiple
selected items from a listbox. Everything I try does not
seem to work. Thanks in advance.
|
by: Jason P Opdycke [MSFT] |
last post by:
Hello All -
I have 2 list boxes. Items in Left list box populated from a DB. I remove
an item from the left box and add an item to the right box to allow user
selection. When that item is...
|
by: Joe Fallon |
last post by:
I have a list box with 7 text values in it.
I have a pair of buttons to Move Up or Move Down the selected item one
position.
What is the simplest way to code the buttons so the item moves one...
|
by: manning_news |
last post by:
Using 2003. How do I tell if a selected item on a multi-select listbox
is now unselected? If a user unselects an item, I want to prompt them
that they've unselected it. No prompt if they're...
| |
by: teo |
last post by:
I have a LISTBOX
how to insert VBTab or Blank spaces ?
in Example
Listbox1.Items.Add ("Hallo" & vbTab & "GoodMorning")
or
Listbox1.Items.Add ("Hallo" & " " & "GoodMorning")
...
|
by: jesse07 |
last post by:
I have 6 seperate listbox and I want the user to select 1 value from 1 of the 6 boxes. The problem is after the user clicks the listbox1 then listbox2, listbox1 still says highlighted. I want to...
|
by: =?Utf-8?B?QmVu?= |
last post by:
How would you add an item with its DisplayMember and ValueMember without
binding to a datatable or dataview like:
listbox.DisplayMember = "name";
listbox.ValueMember = "recid";
listbox.DataSource...
|
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,...
|
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...
|
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,...
| |
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...
|
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: 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: 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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |