-
EditText Listbox subitem
I have two columns, Column one is to reference my layer, Column two is to reference a value.
My array will always sequentially go in order, but my value will always change. So I want to include to the expression below. That if I fill out var input = win.add (“edittext”);
input.active = true;
it will add it to column two if I hit add item.
Then say I got the number wrong. I want it to be another value. If I highlight the row. Refill out var input = win.add (“edittext”);
input.active = true;
then hit insert.It will update it.
I’ve seen scripts that just us insert via editText and scripts that use just arrays. I haven’t found an example that allows the two.
var testArr = [];
startGUI();
function startGUI() {// Main Window
var win = new Window( “palette”, “Test Listbox”, undefined, { resizeable:true } );
win.orientation = “column”;
win.alignChildren = [“fill”, “fill”];// Listbox Group
var grpListbox = win.add(‘group’);
grpListbox.alignChildren = [‘fill’, ‘fill’];var myListbox = addListBox (grpListbox, testArr);
// add ListBox
function addListBox(container, testArr) {
var listbox = container.add(“listbox”, undefined, testArr,
{
numberOfColumns: 2,
showHeaders: true,
columnTitles: [‘Bar’, ‘Value’]
});return listbox;
}var input = win.add (“edittext”);
input.active = true;
var b = win.add (“button”, undefined, “Insert”, {name: “ok”});// BTN: Add Items To Array
var addItem = win.add(“button”, undefined, “Add Item”);
addItem.onClick = function() {
testArr.push (‘Bar’ + ” ” + (testArr.length + 1));
grpListbox.remove(grpListbox.children[0]);
myListbox = addListBox (grpListbox, testArr);
win.layout.layout(true);
//updateListboxArray(myListbox);
//$.writeln (testArr.length + ” ” + myListbox.items.length);
}// BTN: Clear Listbox
var removeAllItems = win.add(“button”, undefined, “Clear Listbox”);
removeAllItems.onClick = function() {
// Clear the array
testArr = [];
updateListboxArray(myListbox);
}// Update listbox items
function updateListboxArray(listbox) {// Clear listbox first
listbox.removeAll();// Create new listbox items from array
var i = 0;
while (listbox.items.length < testArr.length) { listbox.add (“item”, testArr[i]); i++;}
}// Quit BTN
win.quitBtn = win.add(“button”, undefined, “Close”);
win.quitBtn.onClick = function() {
win.close();
}// Window Settings
win.onResizing = function () { this.layout.resize(); };
win.onShow = function () { win.layout.resize(); };
win.center();
win.show();
}
Sorry, there were no replies found.