.ListIndex = -1 causing erratic results

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!
LVL 39
thenelsonAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Michael_DConnect With a Mentor Commented:
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
 
EDDYKTCommented:
You need to do this to clear


For i = 1 To List1.ListCount
List1.Selected(i - 1) = False
Next
0
 
EDDYKTConnect With a Mentor Commented:
By the way are you talking combo box or list box?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Mikal613Commented:
change there style = 2
0
 
thenelsonAuthor Commented:
'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
 
thenelsonAuthor Commented:
Thanks Michael.  
Good info!
0
 
thenelsonAuthor Commented:
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
 
ArkCommented:
Try API instead:
SendMessage list1.hwnd,LB_SETSEL,False,ByVal -1
0
 
Ashutosh VyasFounder, InitQubeCommented:
.listindex = -1 works well for me.
0
 
Michael_DCommented:
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
 
thenelsonAuthor Commented:
A split sounds good to me.

Nelson
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.