Solved

.ListIndex = -1 causing erratic results

Posted on 2004-10-20
12
330 Views
Last Modified: 2010-05-02
On some of my combo boxes (multiselect = extended), with certain items or selection of items selected, [controlname].ListIndex = -1 deselects all the items in the combobox but they stay highlighted.

In other words:  sometimes after using [controlname].ListIndex = -1,  PatientList.ListCount = 0 but the item(s) in the list remains highlighted.

Any suggestions?  Thanks!
0
Comment
Question by:thenelson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +3
12 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12362155
You need to do this to clear


For i = 1 To List1.ListCount
List1.Selected(i - 1) = False
Next
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 250 total points
ID: 12362162
By the way are you talking combo box or list box?
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12362678
change there style = 2
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Author Comment

by:thenelson
ID: 12363987
'For i = 0 To PatientList.ListCount - 1
'    PatientList.Selected(i) = False
'Next i

would be faster than:

For i = 1 To List1.ListCount
List1.Selected(i - 1) = False
Next

(doesn't require the (i-1) calculation with each iteration.)

I'm going for the more elegant, faster solution of .listindex=-1.

It's a combo box.

I need the additional function of style=3.

I meant to put this question in the Access channel -- oh well.
0
 
LVL 13

Accepted Solution

by:
Michael_D earned 250 total points
ID: 12364497
From MSDN:

"For a control in which users can make multiple selections, this property's behavior depends on the number of items selected.If only one item is selected, ListIndex returns the index of that item. In a multiple selection, ListIndex returns the index of the item contained within the focus rectangle, whether or not that item is actually selected."

Therefore setting ListIndex = -1 will not clear .Selected property for items but only will remove the current item from the Box
Even that only in case of simple combo.


Regards,

Michael
0
 
LVL 39

Author Comment

by:thenelson
ID: 12364862
Thanks Michael.  
Good info!
0
 
LVL 39

Author Comment

by:thenelson
ID: 12364877
I made a mistake -- it is a list box.

in another thread, someone suggested using [controlname]=null.  That creates the same condition as .listindex=-1.  Is that also not reliable?
0
 
LVL 28

Expert Comment

by:Ark
ID: 12366698
Try API instead:
SendMessage list1.hwnd,LB_SETSEL,False,ByVal -1
0
 
LVL 8

Expert Comment

by:Ashutosh Vyas
ID: 12397468
.listindex = -1 works well for me.
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 12432681
thenelson tried to find "the more elegant, faster solution of .listindex=-1."
But it isn't perfect world therefor I think EDDYKT gave the right solution
and I have explained why thenelson's method will not work.

So I suggest :
>>> Split
EDDYKT - 250
Michael_D - 250

Best regards,

Michael

0
 
LVL 39

Author Comment

by:thenelson
ID: 12435579
A split sounds good to me.

Nelson
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Modifying Conditional Format from VBA code 3 69
Macro Excel - Multiple If conditions 2 87
MsgBox 4 71
Copy a range from 1..n excel sheets to one destination sheet 2 66
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question