# ListBox selection notification

**URL:** <https://forum.juce.com/t/listbox-selection-notification/5856>\
**Category:** General JUCE discussion\
**Created:** [November 7, 2010, 11:55pm UTC](https://forum.juce.com/t/listbox-selection-notification/5856 "2010-11-07T23:55:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinaiz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dinaiz/32/182_2.png) [@dinaiz](https://forum.juce.com/u/dinaiz)\
**Post date:** [November 7, 2010, 11:55pm UTC](https://forum.juce.com/t/listbox-selection-notification/5856/1 "2010-11-07T23:55:51Z")

</div>

Hi !

I’m just trying to code a quick tool using ListBoxes, but I’m a little bit confused about how the GUI gets notified when the user selects another item in the List.

Basically my (very simple) app is divided in a Model and a View/Controler (a basic MVC). I have a ListBox in the view, and a ListBoxModel in the Model.  
If I change the selection in the ListBox, the ListBoxModel is notified inside the overrided selectedRowsChanged . However, how can I make the other GUI classes aware of a change of selection ?  
In MVC, the model (ListBoxModel in that case) is not supposed to be aware of any GUI class at all, so I can’t call a method from the GUI from ListBoxModel.

I couldn’t find any method in ListBox, that I can override to be notified when the selection changed, and looking at the code, it doesn’t seem to exist any.

What’s the recomended way of doing such things ?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 8, 2010, 9:49am UTC](https://forum.juce.com/t/listbox-selection-notification/5856/2 "2010-11-08T09:49:14Z")

</div>

Allowing multiple listeners to directly listen to a listbox is probably bad design… E.g. if your list is selecting a type of cheese, you’d have an object somewhere of type CheeseManager, and the listboxmodel would call myCheeseManager.setCurrentCheese() when the selection changes. Then, other CheeseListener objects would attach themselves to CheeseManager, and receive callbacks when the cheese changes, which is a far better design than having them directly connected to a listbox.

---

<div class="post-metadata">

**Author:** ![dinaiz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dinaiz/32/182_2.png) [@dinaiz](https://forum.juce.com/u/dinaiz)\
**Post date:** [November 8, 2010, 2:41pm UTC](https://forum.juce.com/t/listbox-selection-notification/5856/3 "2010-11-08T14:41:32Z")

</div>

[quote=“jules”] if your list is selecting a type of cheese[/quote] Haha, do you say that because I’m french ? 🙂

Ok thanks for this input, I can totally see your logic there and it makes sense to me. Thanks !

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 8, 2010, 3:21pm UTC](https://forum.juce.com/t/listbox-selection-notification/5856/4 "2010-11-08T15:21:01Z")

</div>

> [@](#):
>
> Haha, do you say that because I’m french ?

No, I didn’t notice that you were french! But cheese is a useful substance for computing analogies!
