PDA

View Full Version : [SOLVED] Listbox Selection not working with 1 result



GhostofDoom
01-19-2020, 04:11 AM
Hello,

what are we doing wrong ?
it seems it works fine if we have like 2 or more results
it will be selected the last row

but when we have 1 result it don't select anything



'select last row
With ListBox1
For i = .ListCount - 1 To 0 Step -1
If .List(i, 0) <> "" Then
.ListIndex = .ListCount - 1
'or even this code also work with last row
.ListIndex = i
Exit For
End If
Next i
End With


any idea's?

-Thanks

-updated
not working


.SetFocus
.ListIndex(0) = True


'Solved
seems we got our code to more selection instead of 1



If (n - 1) < 2 Then ' this was the problem i had added the code not here but instead under it
ElseIf (n - 1) > 1 Then 'code was here seems the wrong place :banghead:

Artik
01-19-2020, 05:35 PM
Maybe I did not understand the problem, but maybe such a code is enough:
With Me.ListBox1 .ListIndex = .ListCount - 1
End With
Artik

GhostofDoom
01-19-2020, 07:18 PM
Thanks Artik :thumb
this option also work