Skip to content

Instantly share code, notes, and snippets.

@aanastasiou
Created February 3, 2026 17:11
Show Gist options
  • Select an option

  • Save aanastasiou/a2c39f99c0932a7a0be75b06f2f0fe70 to your computer and use it in GitHub Desktop.

Select an option

Save aanastasiou/a2c39f99c0932a7a0be75b06f2f0fe70 to your computer and use it in GitHub Desktop.
Working with gui-easy tables
#lang racket
;; Working with gui-easy tables.
(require
racket/gui
racket/gui/easy
racket/vector)
; Generate a random string of specific length composed of a collection of characters
(define (gen-code alphabet
[length 8])
(build-string length
(lambda (x)
(string-ref alphabet (random 0 (string-length alphabet))))))
; Generate a random data vector
(define (gen-data)
(build-vector 10
(lambda (x)
(vector (number->string x)
(gen-code "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 " (random 4 25))))))
(define sel (obs '())) ;; The actual selection observable
(define shadow-sel (obs '())) ; An observable that temporarily holds the current selection
(define the-data (obs (gen-data))) ; The observable that holds the data of the listbox
;; The table control
(define t-view (table '("IDX" "Content")
the-data
(lambda (the-event some-data sl)
(when (eq? the-event 'select)
(obs-set! shadow-sel sl) ;; Leave this line in to experience the issue
;;(obs-set! sel sl) ;; Uncomment this line (and comment the above) to experience the workaround
))
#:selection sel
#:style '(multiple
column-headers
vertical-label
extended)))
(render
(dialog t-view
#:min-size '(640 480)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment