How to actually set the selected item in a TextList?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
mmmaarten
Posts: 271
Joined: Mon Sep 19, 2022 2:19 pm
Location: Utrecht, The Netherlands
Contact:

How to actually set the selected item in a TextList?

Post by mmmaarten »

Hi,

I am struggling to set the current item in a TextList inside a dialog. Whatever I do it never updates. I tried both setting the ID as well as the Label, but without any result.

Also tried it both with 'redraw' and without:

self.lstSpeedBone:SetItemLabel('Select Bone', false)
self.lstSpeedBone:SetSelItem(0, false)

self.lstSpeedBone:SetItemLabel('Select Bone', true)
self.lstSpeedBone:SetSelItem(0, true)

I don't see anything more I could think of doing to make this work on the documentation here: https://mohoscripting.com/classes/LM_TextList

Also I don't see anything in the documentation about how to set the value per item (https://mohoscripting.com/methods/345), so I can only assume that a zero- or one-based index value is the value per item.

So how to set the selected item???
Adults should play more often
User avatar
hayasidist
Posts: 3524
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: How to actually set the selected item in a TextList?

Post by hayasidist »

? LM_TextList:SetSelItem(id, redraw)
or maybe a bit more context (e.g. how is self.lstSpeedBone defined?)
User avatar
mmmaarten
Posts: 271
Joined: Mon Sep 19, 2022 2:19 pm
Location: Utrecht, The Netherlands
Contact:

Re: How to actually set the selected item in a TextList?

Post by mmmaarten »

hayasidist wrote: Wed Dec 06, 2023 10:10 am ? LM_TextList:SetSelItem(id, redraw)
or maybe a bit more context (e.g. how is self.lstSpeedBone defined?)
I tried that exact thing a thousand times by now, but it doesn't work here.
What context would you like to see? It's inside a SimpleDialog
Adults should play more often
User avatar
hayasidist
Posts: 3524
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: How to actually set the selected item in a TextList?

Post by hayasidist »

well, like I said, a start would be to see how self.lstSpeedBone is defined - but ideally the whole dialogue

if lstSpeedBone is a dropdown (LM.GUI.Menu) then maybe SetChecked() would be the right answer -- but if it's defined in a way that needs the SetSelItem() ...?
User avatar
mmmaarten
Posts: 271
Joined: Mon Sep 19, 2022 2:19 pm
Location: Utrecht, The Netherlands
Contact:

Re: How to actually set the selected item in a TextList?

Post by mmmaarten »

hayasidist wrote: Wed Dec 06, 2023 11:45 am well, like I said, a start would be to see how self.lstSpeedBone is defined - but ideally the whole dialogue

if lstSpeedBone is a dropdown (LM.GUI.Menu) then maybe SetChecked() would be the right answer -- but if it's defined in a way that needs the SetSelItem() ...?
I'll send the file via discord PM so you can see it.
Adults should play more often
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: How to actually set the selected item in a TextList?

Post by Rai López »

FYI, there is a known bug for which is not possible to make work SetSelItem() by feeding it with an ID. It's unfortunate there are some issues with LM.GUI.ImageTextList kind of widgets (I'll try to also add a note for this one there) given their usefulness... but (fortunately!) its variant :arrow: SetSelItem(label, redraw, addToSelection) has done the job, for me at least, in most cases by using it, e.g., this way:

Code: Select all

d.textList:SetSelItem(d.textList:GetItem(0), true, false))
A little less handy, of course... but a workaround to can get, in this case, list's first item selected after all, only by means of using its label instead. 🤔 I wrote all speaking from memory and assuming this behavior affects LM_TextList in the same way, but LM_ImageTextList offers more possibilities anyway, so hope it still helps.
...
User avatar
mmmaarten
Posts: 271
Joined: Mon Sep 19, 2022 2:19 pm
Location: Utrecht, The Netherlands
Contact:

Re: How to actually set the selected item in a TextList?

Post by mmmaarten »

Rai López wrote: Wed Dec 06, 2023 6:52 pm FYI, there is a known bug for which is not possible to make work SetSelItem() by feeding it with an ID. It's unfortunate there are some issues with LM.GUI.ImageTextList kind of widgets (I'll try to also add a note for this one there) given their usefulness... but (fortunately!) its variant :arrow: SetSelItem(label, redraw, addToSelection) has done the job, for me at least, in most cases by using it, e.g., this way:

Code: Select all

d.textList:SetSelItem(d.textList:GetItem(0), true, false))
A little less handy, of course... but a workaround to can get, in this case, list's first item selected after all, only by means of using its label instead. 🤔 I wrote all speaking from memory and assuming this behavior affects LM_TextList in the same way, but LM_ImageTextList offers more possibilities anyway, so hope it still helps.
Thanks a lot for the useful info!
I just tried it on TextList and it does NOT work. But when using the ImageTextList instead, it DOES work. So the only thing left for me now is to conclude that this indeed is a bug in the api.

Luckily ImageTextList seems to work exactly the same and I only needed to replace TextList with ImageTextList.

Thanks again!
Adults should play more often
User avatar
hayasidist
Posts: 3524
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: How to actually set the selected item in a TextList?

Post by hayasidist »

Rai López wrote: Wed Dec 06, 2023 6:52 pm FYI, there is a known bug for which is not possible to make work SetSelItem() by feeding it with an ID. It's unfortunate there are some issues with LM.GUI.ImageTextList kind of widgets (I'll try to also add a note for this one there) given their usefulness... but (fortunately!) its variant :arrow: SetSelItem(label, redraw, addToSelection) has done the job, for me at least, in most cases by using it, e.g., this way:

Code: Select all

d.textList:SetSelItem(d.textList:GetItem(0), true, false))
A little less handy, of course... but a workaround to can get, in this case, list's first item selected after all, only by means of using its label instead. 🤔 I wrote all speaking from memory and assuming this behavior affects LM_TextList in the same way, but LM_ImageTextList offers more possibilities anyway, so hope it still helps.
Hey Ramon -- is that issue logged in the usual place?? I just looked and couldn't see anything that matched????
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: How to actually set the selected item in a TextList?

Post by Rai López »

mmmaarten wrote: Wed Dec 06, 2023 10:08 pm Luckily ImageTextList seems to work exactly the same and I only needed to replace TextList with ImageTextList.
Thanks again!
You're welcome! And yes, everything you were already doing should work the same, plus ImageTextLists are superior to TextLists in all senses I can think, so for now I think it's more a matter of at least being aware of the issue.

hayasidist wrote: Wed Dec 06, 2023 10:19 pm Hey Ramon -- is that issue logged in the usual place?? I just looked and couldn't see anything that matched????
Indeed at some point it was, but turns out that for the previous version... Fortunately, I found the text saved as a note (😌), so reporting it again will be a matter of seconds.

EDIT: All done!
...
User avatar
hayasidist
Posts: 3524
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: How to actually set the selected item in a TextList?

Post by hayasidist »

Rai López wrote: Wed Dec 06, 2023 11:05 pm
EDIT: All done!
:D and thanks for the history links...
User avatar
mmmaarten
Posts: 271
Joined: Mon Sep 19, 2022 2:19 pm
Location: Utrecht, The Netherlands
Contact:

Re: How to actually set the selected item in a TextList?

Post by mmmaarten »

hayasidist wrote: Wed Dec 06, 2023 10:19 pm Hey Ramon -- is that issue logged in the usual place?? I just looked and couldn't see anything that matched????
FYI I also had created a ticket for it
Adults should play more often
Post Reply