# ListBox

**URL:** <https://forum.juce.com/t/listbox/1062>\
**Category:** General JUCE discussion\
**Created:** [September 17, 2006, 6:26pm UTC](https://forum.juce.com/t/listbox/1062 "2006-09-17T18:26:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haydxn](https://avatars.discourse-cdn.com/v4/letter/h/5fc32e/32.png) [@haydxn](https://forum.juce.com/u/haydxn)\
**Post date:** [September 17, 2006, 6:26pm UTC](https://forum.juce.com/t/listbox/1062/1 "2006-09-17T18:26:56Z")

</div>

What is the recommended way of dealing with custom components for custom ListBoxes now? In particular, i mean handling mouse clicks to select them.

The components are created in the refreshComponentForRow, that happens fine. I presume it needs to register mouse events or something… but who with? My guess is that i update the component to know what row it is, and give it a pointer to the ListBox (assuming that the ListBoxModel class i’m making is also inheriting ListBox), and get it to call selectRow(row) on a mouseDown.

If this is indeed what is required each time, i think it would be very handy to have included with juce a base ListBoxItem component, which has bool selected and int currentRow members and functions, with a default mouseDown implementation to select the row (also taking a pointer to the ListBox in the constructor). Not that it’s that much hassle to make one myself of course. Just thinking out loud!

---

<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:** [September 18, 2006, 11:25am UTC](https://forum.juce.com/t/listbox/1062/2 "2006-09-18T11:25:45Z")

</div>

No need to register for mouse events, just give your component a mouseDown() method and use that to call selectRowsBasedOnModifierKeys().

I guess a base class would be useful, though I’m sure I tried to write one before and found there wasn’t a neat way of doing a generic one. I’ll pop this on my to-do list as something to have another look at.

---

<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:** [May 12, 2017, 10:00am UTC](https://forum.juce.com/t/listbox/1062/3 "2017-05-12T10:00:09Z")

</div>

Closed on May 12, 2017, 10:00am UTC


