Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

Determining the index of selected items in a ListBox?

$
0
0

Hello,

I can't seem to figure out a simple/direct method to identify the index of the selected item in a list box.

I feel like I'm missing something, but I can't seem to figure which (if any) property returns an index number if you use it with the .onChange callback for a ListBox.

The following code accomplishes what I need but isn't particularly efficient or elegant and can get muddled if you introduce multiple lists to check.

Any suggestions to duplicate this same behavior with better code would be appreciated.

Thanks!

 

 

var res = "palette {text: 'Example List', properties:{resizeable:true}\

pnl: Panel{orientation: 'row',preferredSize: [400,600],\

list1: ListBox{preferredSize: [400,550], properties:{multiselect:true,numberOfColumns:2, showHeaders:true,columnTitles: ['List 1', 'Subitem 0']}},\

}}"

 

 

var win = new Window(res)

win.show()

for (i=0; i<10;i++) {

    var row = win.pnl.list1.add('item', "Same Entry")

    row.subItems[0].text = "Subitem "+i}

 

 

win.pnl.list1.onChange = function() {

     var tempArray = new Array()

     for (i=0; i<win.pnl.list1.items.length;i++) {

         if (win.pnl.list1.items[i].selected == true){tempArray.push(i)}

         }

    var selectedRow = win.pnl.list1.items[tempArray[0]].text

    var selectedRowSubitem = win.pnl.list1.items[tempArray[0]].subItems[0]

              alert("Selection: "+tempArray+"\n Displayed Contents:   "+selectedRow+"\t"+selectedRowSubitem)

            

     }


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>