# Multiple selection and right click on TableListBox

**URL:** <https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475>\
**Category:** General JUCE discussion\
**Created:** [January 7, 2008, 10:57am UTC](https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475 "2008-01-07T10:57:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ring2](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ring2](https://forum.juce.com/u/ring2)\
**Post date:** [January 7, 2008, 10:57am UTC](https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475/1 "2008-01-07T10:57:54Z")

</div>

Hi Jules,

A happy new year.

When multiple rows on the TableListBox are selected and right click one of them, other rows are de-selected before TableListBoxModel::cellClicked() is called.

I think this is not good behavior when the application need to do the action for selected rows by right click.

How about changing return type of TableListBoxModel::cellClicked() to bool instead of void? If the return value is true, TableListBox won’t change the row selection if the clicked row was selected, etc.

Best regards,  
Masanao Hayashi

---

<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:** [January 7, 2008, 11:54am UTC](https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475/2 "2008-01-07T11:54:49Z")

</div>

Happy new year!

Good point… I think the best fix would be this tweak to juce\_ListBox.cpp:

`void ListBox::selectRowsBasedOnModifierKeys (const int row,
                                             const ModifierKeys& mods)
{
    if (multipleSelection && mods.isCommandDown())
    {
        flipRowSelection (row);
    }
    else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
    {
        selectRangeOfRows (lastRowSelected, row);
    }
    else if (! mods.isPopupMenu())
    {
        selectRowInternal (row, false, true, true);
    }
}
`

---

<div class="post-metadata">

**Author:** ![ring2](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ring2](https://forum.juce.com/u/ring2)\
**Post date:** [January 8, 2008, 7:36am UTC](https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475/3 "2008-01-08T07:36:11Z")

</div>

Thanks!

I think this one is more better, it gives us the same behavior as Mac OS X Finder, iTunes and Windows Explorer, etc.

`void ListBox::selectRowsBasedOnModifierKeys (const int row,
                                             const ModifierKeys& mods)
{
    if (multipleSelection && mods.isCommandDown()) 
    { 
        flipRowSelection (row); 
    } 
    else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0) 
    { 
        selectRangeOfRows (lastRowSelected, row); 
    } 
    else if ((!mods.isPopupMenu()) || (!isRowSelected(row)))
    {
        selectRowInternal (row, false, true, true); 
    } 
} 
`[/quote]

---

<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:** [January 8, 2008, 12:29pm UTC](https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475/4 "2008-01-08T12:29:23Z")

</div>

ah yes, that’s even better.

---

<div class="post-metadata">

**Author:** ![ring2](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@ring2](https://forum.juce.com/u/ring2)\
**Post date:** [January 10, 2008, 4:32am UTC](https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475/5 "2008-01-10T04:32:07Z")

</div>

Thanks. 🙂  
Could you choose this solution in JUCE v1.46?

- Masa

---

<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:** [January 10, 2008, 9:19am UTC](https://forum.juce.com/t/multiple-selection-and-right-click-on-tablelistbox/2475/6 "2008-01-10T09:19:12Z")

</div>

Yes, no problem.
