[racket] How can I get "data" from list-box% ?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Oct 11 08:11:10 EDT 2014

At Sat, 11 Oct 2014 09:10:44 +0800, zhang peipei wrote:
> #lang racket
> (require racket/GUI)
> (define main-frame (new frame%
>                         [label "main"]))
> 
> (define test (new list-box%
>                   [label ""]
>                   [choices (list "hello" "world")]
>                   [columns '("key" "value")]
>                   [parent main-frame]
>                   [style (list 
>                           'variable-columns
>                           'single
>                           'column-headers
>                           'clickable-headers
>                           'vertical-label)]))
> 
> (send main-frame show #t)
> ;It shows:
> ;key    value
> ;hello
> ;world
> (send test get-string 1)
> ;Result:
> ;world
> 
> (send test set (list "1" "2" "3") (list "4" "5" "6")) ;It shows ;key value
> ;1   4
> ;2   5
> ;3   6
> (send test get-string 1)
> ;Result
> ;2
> 
> My question is:
> How can I get the "value" of the value column in the list-box ?

There's not currently a method to extract the content of columns beyond
the first one.

That omission is partly a historical artifact, but it's also usually
better to keep your data in a separate model and reflect it to the
list-box as a view (that's "write-only" from the program's
perspective). In other words, I recommend having a `set-table!`
function that both stores revised table content and also updates the
`list-box%`, plus then a `get-...` function that reads information from
the table content without consulting the `list-box%`.

If you really want to keep state in the `list-box%`, you could use the
`set-data` and `get-data` methods to associate a value with each row in
the list box, where the value covers the information in all columns.


Posted on the users mailing list.