Function Repository Resource:

GridPicker

Source Notebook

A ListPicker for grids

Contributed by: Michael Sollami

ResourceFunction["GridPicker"][list,{val1,val2,}]

represents a grid pane with setting list that can contain possible values vali.

ResourceFunction["GridPicker"][Dynamic[list],{val1,val2,}]

represents a grid pane that dynamically updates list, with members added or removed each time an item is selected or deselected.

ResourceFunction["GridPicker"][Dynamic[list],{val1,val2,},columns]

formats the grid pane with the indicated number of columns.

Details and Options

Unlike ListPicker there is no need to hold the   key for multiselection.
When specifying the grid dimensions rows and/or columns should be positive integers or Automatic.
ResourceFunction["GridPicker"] accepts any option of Grid, as well as the following additional options:
"ReturnPositions"Falsespecifies whether to return selected items or their positions
"SelectionStyle"Automaticspecifies the style to use for highlighting selected items

Examples

Basic Examples (1) 

Select letters from the English alphabet:

In[1]:=
letters = {"a", "e", "i", "o", "u"};
Labeled[Panel@
  ResourceFunction["GridPicker"][Dynamic[letters], Alphabet[], 8, Spacings -> {1, 1}], Dynamic[letters], Top]
Out[2]=

Scope (3) 

You can use any expressions in GridPicker:

In[3]:=
disks = {};
In[4]:=
Dynamic@disks
Out[4]=
In[5]:=
ResourceFunction["GridPicker"][Dynamic[disks], Table[Graphics[{Hue@RandomReal[], Disk[]}, ImageSize -> 18], {24}],
   8, "SelectionStyle" -> Darker@Gray]
Out[5]=

Set the background color for selected items:

In[6]:=
countries = RandomEntity[EntityClass["Country", "Countries"], 16];
selected = RandomSample[countries, 5];
Grid@{{
   Panel@ResourceFunction["GridPicker"][Dynamic[selected], countries, 2, "SelectionStyle" -> LightGreen, Spacings -> {.5, .5}], Spacer[30], Dynamic[Framed[Multicolumn[selected], RoundingRadius -> 5, Background -> LightGreen]]}}
Out[8]=

Use GridPicker with images to select your favorite photos from a batch:

In[9]:=
fav = {};
imgs = Table[ResourceFunction["RandomPhoto"][], 15];
In[10]:=
ResourceFunction["GridPicker"][Dynamic[fav], imgs, 5]
Out[10]=
In[11]:=
ImageCollage[fav]
Out[11]=

Options (1) 

Use the option "ReturnPositions" to get the positions rather than the selected items themselves:

In[12]:=
positions = {};
In[13]:=
Dynamic@positions
Out[13]=
In[14]:=
ResourceFunction["GridPicker"][Dynamic[positions], Table[Prime[i], {i, 18}],
   6, "SelectionStyle" -> Hue[.5], "ReturnPositions" -> True]
Out[14]=

Publisher

Michael Sollami

Version History

  • 1.0.0 – 20 April 2020

Related Resources

License Information