# Racket/gui list-box% vs choice% append

**URL:** <https://racket.discourse.group/t/racket-gui-list-box-vs-choice-append/3516>\
**Category:** Questions & Answers\
**Created:** [January 26, 2025, 9:51am UTC](https://racket.discourse.group/t/racket-gui-list-box-vs-choice-append/3516 "2025-01-26T09:51:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gekkonier](https://avatars.discourse-cdn.com/v4/letter/g/f9ae1b/32.png) [@gekkonier](https://racket.discourse.group/u/gekkonier)\
**Post date:** [January 26, 2025, 9:51am UTC](https://racket.discourse.group/t/racket-gui-list-box-vs-choice-append/3516/1 "2025-01-26T09:51:46Z")

</div>

Hi!

This is my first post, so I hope I don't violate something here. If this does not fit here I hope you tell me so I can adapt.

I enjoy programming small tools with Racket, and I really like the easy to use gui Racket offers out of the box. The "standard library" is impressive, it's useful and the documentation is top!

However, I stumbled across a small issue (well, I can sail around it, but I don't think that should be necessary). I can append data to a list-box%, but not to a choice%.

```scheme
#lang racket
(require racket/gui)

(define frame (new frame% [label "Example"]))

; a simple listbox
(define my-list-box
  (new list-box%
       [parent frame]
       [label "my listbox:"]
       [choices '()]))

; i can append an entry and assign a value to this entry
(send my-list-box append "hello" 123)

; later on i can access this data:
(send my-list-box get-data 0) ; this will return 123

; now, a choice%
(define my-choice
 (new choice%
      [parent frame]
      [label "select something:"]
      [choices '()]))

#|

this does not work:

   (send my-choice append "other hello" 123)

it throws:

-append method in basic-list-control%: arity mismatch;
 the expected number of arguments does not match the given number
  expected: 1
  given: 2

I can only do (send my-choice append "whatever")

|#

(send frame show #t)

```

I like to use the appended data to store perhaps table id's.  
At the moment I just use list-box% instead of choice%, because I'm lazy to sail around.  
The UI gets a bit hideous, but that's no matter.

But I'm curious, now, my question:  
How would you implement such a functionality?  
A in memory table that maps values to choice items? Inherit choice% and do it there? That would be my first thoughts, but I would like to get other opinions too.

Thank you very much for your time!

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [January 26, 2025, 4:57pm UTC](https://racket.discourse.group/t/racket-gui-list-box-vs-choice-append/3516/2 "2025-01-26T16:57:06Z")

</div>

The docs and the `case-lambda` in the library agree with your reasoning. You may want to open a GH issue at

[https://github.com/racket/racket](https://github.com/racket/racket)

(FIWI, if you right click on `list-box%` in DrRacket you can open the library. The bottom-most class is the one your code instantiates. The `-append` definition using `case-lambda` is the one your code is sending a message to. But, the second clause then dives into the `wx` layer and seems to call back the `-append` from the superclass, and that one takes only one argument.)

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [January 26, 2025, 6:50pm UTC](https://racket.discourse.group/t/racket-gui-list-box-vs-choice-append/3516/3 "2025-01-26T18:50:06Z")

</div>

Ouch, I am silly.

```scheme
(send my-list-box append "other hello" 123)

```

Your code sent the message to the wrong object. No issue needed.

---

<div class="post-metadata">

**Author:** ![gekkonier](https://avatars.discourse-cdn.com/v4/letter/g/f9ae1b/32.png) [@gekkonier](https://racket.discourse.group/u/gekkonier)\
**Post date:** [January 26, 2025, 7:00pm UTC](https://racket.discourse.group/t/racket-gui-list-box-vs-choice-append/3516/4 "2025-01-26T19:00:44Z")

</div>

I found

```scheme
Overrides append in list-control<%>.

Adds a new item to the list box with an associated “data” object. The data object is not displayed in the list box; it is provided merely as a convenience for use with get-data, possibly allowing a programmer to avoid managing a separate item-to-data mapping in addition to the list box control.

See also append in list-control<%>.

```

It seems to me list-box% is the only widget that does have that functionality.  
I try to implement the mentioned item-to-data mapping myself, shouldn't be hard to do.

Thank you, G!
