Page 1 of 1

How to actually set the selected item in a TextList?

Posted: Wed Dec 06, 2023 9:19 am
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???

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

Posted: Wed Dec 06, 2023 10:10 am
by hayasidist
? LM_TextList:SetSelItem(id, redraw)
or maybe a bit more context (e.g. how is self.lstSpeedBone defined?)

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

Posted: Wed Dec 06, 2023 10:31 am
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

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

Posted: Wed Dec 06, 2023 11:45 am
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() ...?

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

Posted: Wed Dec 06, 2023 1:28 pm
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.

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

Posted: Wed Dec 06, 2023 6:52 pm
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.

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

Posted: Wed Dec 06, 2023 10:08 pm
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!

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

Posted: Wed Dec 06, 2023 10:19 pm
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????

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

Posted: Wed Dec 06, 2023 11:05 pm
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!

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

Posted: Thu Dec 07, 2023 11:31 am
by hayasidist
Rai López wrote: Wed Dec 06, 2023 11:05 pm
EDIT: All done!
:D and thanks for the history links...

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

Posted: Mon Dec 11, 2023 1:30 pm
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