Page 1 of 1

How to select entries in ListBox in SingleSelect Mode?

Posted: 24 Aug 2010, 14:21
by Rucksacktraeger
I could select an Entry this way:

Code: Select all

LstU.ListItems(3).Selected = True 'Markiert Item 4
but why only in MultiSelect Mode? If I am not in MultiSelect Mode, how can I select Entries? With Select I mean to put the Caret on the selected position AND get the Background blue.

In MultiSelectMode 0 I get an error like this: Method 'Selected' for the Object 'IListBoxItem' failed (translated from german)


Btw: I tried the Unicode Listbox a lot and I played also with this:

Code: Select all

MsgBox LstU.SelectedItem.Index '3
MsgBox LstU.ListItems.Item(3).Index '3
MsgBox LstU.CaretItem.Index '3
MsgBox LstU.CaretItem.Selected 'wahr

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 24 Aug 2010, 17:42
by TiKu
Try this:

Code: Select all

Set LstU.SelectedItem = <YourItem>

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 25 Aug 2010, 05:26
by Rucksacktraeger
Thanks, that helped me!
This is my result for anyone with the same Problem:

MultiSelect = 1 or 2

Code: Select all

'    Select
    LstU.MultiSelect = msNormal
    LstU.ListItems(3).Selected = True 'Markiert Item 4
    LstU.ListItems(5).Selected = True 'Markiert Item 6

'    Deselect ALL
    LstU.DeselectItems 'funzt nur bei MultiSelect

'    Deselect one entry ???
MultiSelect = 0

Code: Select all

'   Select
    LstU.MultiSelect = msNone
    Set LstU.SelectedItem = LstU.ListItems.Item(3)

'   Deselect
    LstU.AllowItemSelection = Not LstU.AllowItemSelection 'Trick 17 to loose the Selection (the blue background)
    LstU.AllowItemSelection = Not LstU.AllowItemSelection

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 25 Aug 2010, 06:34
by TiKu
Rucksacktraeger wrote:

Code: Select all

'    Deselect one entry ???

Code: Select all

LstU.ListItems(5).Selected = False
Rucksacktraeger wrote:

Code: Select all

'   Deselect
    LstU.AllowItemSelection = Not LstU.AllowItemSelection 'Trick 17 to loose the Selection (the blue background)
    LstU.AllowItemSelection = Not LstU.AllowItemSelection

Code: Select all

Set LstU.SelectedItem = Nothing

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 05 Jan 2017, 11:11
by Rucksacktraeger
Hi,

this thread is quite old. But I have to change the old project and I ran again into the problem I had a couple of years ago.

I am in SingleEntry Mode and I can select an entry with this:
Set LstU.SelectedItem = <YourItem>

But I could NOT select a specific row (back than and now.)
LstU.ListItems(5).Selected = False

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 05 Jan 2017, 11:14
by TiKu
LstU.ListItems(5).Selected = False will work in multi-selection mode only.

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 05 Jan 2017, 11:40
by Rucksacktraeger
yeah, so is there really no chance to select a specific row by rownumber?

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 05 Jan 2017, 14:48
by TiKu
You can do this:
Set LstU.SelectedItem = LstU.ListItems(5)

Doesn't it work?

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 05 Jan 2017, 15:44
by Rucksacktraeger
Wow. Thanks!!!

Re: How to select entries in ListBox in SingleSelect Mode?

Posted: 05 Jan 2017, 16:25
by TiKu
Ah, and to remove the selection, just set SelectedItem to Nothing.