#1565 How to add items to a Combo

tamer Wed 29 Jun 2011

Hi, I just installed Fantom 2 hours ago. I need to know how to add items to a combo box from code I know that I can add the whole list at once using

x:=Combo{text="pods available"} x.items=Pod.list

But I wanted to do something like :

x:=Combo{text="pods available"} Pod.list.each |pod , int| { x.items.add(pod) }

which compile successfully but generates a runtime error saying "List is readonly":

sys::ReadonlyErr: List is readonly

fan.sys.List.modify (List.java:1295)
fan.sys.List.insert (List.java:369)
fan.sys.List.add (List.java:347)
test::Main.main (Main.fan:30)
fan.sys.List.each (List.java:532)
test::Main.main (Main.fan:28)
java.lang.reflect.Method.invoke (Method.java:597)
fan.sys.Method.invoke (Method.java:552)
fan.sys.Method$MethodFunc.callList (Method.java:198)
fan.sys.Method.callList (Method.java:138)
fanx.tools.Fan.callMain (Fan.java:135)
fanx.tools.Fan.executeType (Fan.java:102)
fanx.tools.Fan.execute (Fan.java:38)
fanx.tools.Fan.run (Fan.java:250)
fanx.tools.Fan.main (Fan.java:288)

andy Wed 29 Jun 2011

You need to set the list in a single op - not modify it - so something like this:

list := [,]
10.times |i| { list.add(i) }
Combo { items=list }

In your case you can simply do:

x := Combo { text="pods available"; items=Pod.list }

Map is useful in these cases as well:

Combo { items = Pod.list.map |p| { "$p.name - $p.version" } }

Login or Signup to reply.