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

Moving list item to index 0

Engaged ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

Hello everyone, how do I move the selected item to "index 0" in the list?

 

Capturar.PNG

var w = new Window ("dialog", "Rearrange");
var list = w.add ("listbox", undefined, ["one", "two", "three", "four", "five"]);
list.selection = 1;
var up = w.add ("button", undefined, "Index 0");

up.onClick = function () {
 var n = list.selection.index;
 if (n > 0) {
 swap (list.items [n-1], list.items [n]);
 list.selection = n-1;
 }
}

function swap (x, y) {
 var temp = x.text;
 x.text = y.text;
 y.text = temp;
}
w.show ();

 

TOPICS
Actions and scripting

Views

377

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

Guide , Jun 29, 2022 Jun 29, 2022
var w = new Window ("dialog", "Rearrange");
var list = w.add ("listbox", undefined, ["one", "two", "three", "four", "five"]);
list.selection = 1;
var up = w.add ("button", undefined, "Index 0");

up.onClick = function () {
 var n = list.selection.index;
 if (n > 0) {
 swap (list.items [0], list.items [n]);
 list.selection = 0;
 }
}

function swap (x, y) {
 var temp = x.text;
 x.text = y.text;
 y.text = temp;
}
w.show ();

Votes

Translate

Translate
Adobe
Guide ,
Jun 29, 2022 Jun 29, 2022

Copy link to clipboard

Copied

var w = new Window ("dialog", "Rearrange");
var list = w.add ("listbox", undefined, ["one", "two", "three", "four", "five"]);
list.selection = 1;
var up = w.add ("button", undefined, "Index 0");

up.onClick = function () {
 var n = list.selection.index;
 if (n > 0) {
 swap (list.items [0], list.items [n]);
 list.selection = 0;
 }
}

function swap (x, y) {
 var temp = x.text;
 x.text = y.text;
 y.text = temp;
}
w.show ();

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 ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

Perfect! Thanks for solving my problem. @jazz-y  taking advantage of this topic here, I took the opportunity to ask you, how would I move any item to the final index of the 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
Guide ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

var w = new Window ("dialog", "Rearrange");
var list = w.add ("listbox", undefined, ["one", "two", "three", "four", "five"]);
list.selection = 1;
var up = w.add ("button", undefined, "Index 0");

up.onClick = function () {
 var n = list.selection.index;
 if (n >= 0) {
 swap (list.items [n], list.items [list.items.length-1]);
 list.selection = list.items.length-1;
 }
}

function swap (x, y) {
 var temp = x.text;
 x.text = y.text;
 y.text = temp;
}
w.show ();

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 ,
Jun 30, 2022 Jun 30, 2022

Copy link to clipboard

Copied

LATEST

@jazz-y thanks again brother

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