• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

How to replace items in a drop-down list

Engaged ,
May 15, 2022 May 15, 2022

Copy link to clipboard

Copied

Hello friend!
In my studies I learned how to add or remove items in a dropdown list, but I couldn't find any article that shows how to replace a selected item. How to replace items?

var dlg = new Window("dialog"); 
dlg.text = "Dialog";dlg.orientation = "column"; 

var list_array = ["Banana","Orange","Melon"];
var list = dlg.add("dropdownlist", undefined, undefined, {name: "list", items: list_array}); 
list.selection = 0; 
list.preferredSize.width = 100; 

var et1 = dlg.add('edittext {properties: {name: "et1"}}'); 
et1.preferredSize.width = 100; 

var b1 = dlg.add("button", undefined, undefined, {name: "b1"}); 
b1.text = "To replace";

b1.onClick = function(){
    var  m = "replace " + list.selection.text + " for " +  et1.text + "  in the drop-down list";
    alert (m.toUpperCase())
}


dlg.show();
TOPICS
Actions and scripting

Views

734

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 16, 2022 May 16, 2022

Insert as first line to b1.onClick:

list.selection.text = et1.text

Votes

Translate

Translate
Adobe
Community Expert ,
May 15, 2022 May 15, 2022

Copy link to clipboard

Copied

You need to delete all items and then add the new list.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 15, 2022 May 15, 2022

Copy link to clipboard

Copied

 

replace()
function replace(){
list.remove(list.selection);
list.add("item", et1.text );
list.selection = list.items.length-1;
}

 

Hi @Chuck Uebele , thanks for the tip, I had tried something like this, it worked 50% desirable, the problem is that the item doesn't stay in the previous order

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 15, 2022 May 15, 2022

Copy link to clipboard

Copied

You have to add them all back, one by one, in the order that you want them. It would be nice to be able to insert one, but that doesn't work, as far as I know. I normally put them all back into an array, then  create a loop to add them all back one at a time, in order. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 15, 2022 May 15, 2022

Copy link to clipboard

Copied

@Chuck Uebele I confess that I have little knowledge about arrays, I certainly won't be able to do it myself, could you kindly show this in practice using my script above?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

quote

 It would be nice to be able to insert one, but that doesn't work, as far as I know.


By @Chuck Uebele

 

Pay attention to the third parameter of the list.add() function

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Third? I found only 2 ('item' and name of that item), but that lets add only, not insert 😞

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

000.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

LATEST

You are right for once again and actually like always!

I looked at add() for containerObj.(type [, bounds, text, { creation_props> } ]);

As I didn't notice the 'dropdownlist' note was referring me to other page I didn't go to 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Insert as first line to b1.onClick:

list.selection.text = et1.text

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

@Kukurykus  homem você está cada dia mais espetacular em suas soluções. Sou muito grato a toda esta comunidade, especialmente a você. Grande colaborador. Obrigado

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

You're right, and I'm the LIVING LEGEND! I like this name much more than previous title 😛

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines