How to actually set the selected item in a TextList?
Moderators: Víctor Paredes, Belgarath, slowtiger
How to actually set the selected item in a TextList?
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???
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
- hayasidist
- Posts: 3586
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How to actually set the selected item in a TextList?
? LM_TextList:SetSelItem(id, redraw)
or maybe a bit more context (e.g. how is self.lstSpeedBone defined?)
or maybe a bit more context (e.g. how is self.lstSpeedBone defined?)
Re: How to actually set the selected item in a TextList?
I tried that exact thing a thousand times by now, but it doesn't work here.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?)
What context would you like to see? It's inside a SimpleDialog
Adults should play more often
- hayasidist
- Posts: 3586
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How to actually set the selected item in a TextList?
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() ...?
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?
I'll send the file via discord PM so you can see it.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() ...?
Adults should play more often
Re: How to actually set the selected item in a TextList?
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
SetSelItem(label, redraw, addToSelection) has done the job, for me at least, in most cases by using it, e.g., this way:
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.
![Arrow :arrow:](./images/smilies/icon_arrow.gif)
Code: Select all
d.textList:SetSelItem(d.textList:GetItem(0), true, false))
...
Re: How to actually set the selected item in a TextList?
Thanks a lot for the useful info!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 variantSetSelItem(label, redraw, addToSelection) has done the job, for me at least, in most cases by using it, e.g., this way:
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.Code: Select all
d.textList:SetSelItem(d.textList:GetItem(0), true, false))
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.
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
- hayasidist
- Posts: 3586
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How to actually set the selected item in a TextList?
Hey Ramon -- is that issue logged in the usual place?? I just looked and couldn't see anything that matched????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 variantSetSelItem(label, redraw, addToSelection) has done the job, for me at least, in most cases by using it, e.g., this way:
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.Code: Select all
d.textList:SetSelItem(d.textList:GetItem(0), true, false))
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?
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.
Indeed at some point it was, but turns out that for the previous version... Fortunately, I found the text saved as a note (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????
EDIT: All done!
...
- hayasidist
- Posts: 3586
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: How to actually set the selected item in a TextList?
FYI I also had created a ticket for ithayasidist 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????
Adults should play more often