MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: Can nobody help me? Re: selecting a column in a grid

  • To: mathgroup at
  • Subject: [mg98326] RE: [mg98312] Re: Can nobody help me? Re: selecting a column in a grid
  • From: "Paul Ellsmore" <paul.ellsmore at>
  • Date: Mon, 6 Apr 2009 05:01:04 -0400 (EDT)
  • References: <gr6c5c$ppo$> <>

Thanks Sjoerd,

Unfortunately, this approach has a problem for me, and I have to admit I
don't know why it works at all!

The following example shows my problem (I think I have adapted your code to
use a user-defined list of data properly):
myData = {{aasdfpppppppppppp, bbbbbbbbb, c}, {dasdf, "", f}, 
       {gasdf, h, i}}; 
Grid[Table[DynamicModule[{col = Black, pos = {i, j}}, 
       EventHandler[Style[myData[[i, j]], FontColor -> Dynamic[col]], 
         {"MouseDown" :> (clickpos = pos; col = Red), 
           "MouseUp" :> (col = Black)}]], {i, 3}, {j, 3}], 
 Frame -> All, 
   BaseStyle -> {Editable -> False, Selectable -> False}]

In the grid that results, the cell selection only works if the mouse is
clicked inside the text in the cell, not in any whitespace, and the empty
cell cannot be selected at all. This is a problem for me. But how does it
work anyway? Eventhandler seems to be wrapped around the cell contents,
rather than the cell itself, but why is there a dynamic value of {i,j}
associated with the cell? I assume that it is something to do with the fact
that pos is defined within Dynamic, but how does the code know what value of
{i,j} is associated with each block of displayed text? Is this some normal
behaviour of Table that I was not aware of, and where would I look to find
more information about this behaviour? More to the point, is there a way of
forcing each CELL to take the value of {i,j}, because this would solve my
problem instantly?

Incidentally, if you double-click in the empty cell, the whole table goes
blue - why is that? 

Many thanks, but I still cannot believe that such a simple task is proving
to be so complicated.



-----Original Message-----
From: Sjoerd C. de Vries [mailto:sjoerd.c.devries at] 
Sent: 05 April 2009 11:40
To: mathgroup at
Subject: [mg98326] [mg98312] Re: Can nobody help me? Re: selecting a column in a grid

Hi Paul,

Cool down ;-) Try this for inspiration:

   {col=Black, pos = {i, j}},
    Style[RandomInteger[{0, 1000000}], FontColor -> Dynamic[col]],
    {"MouseDown" :> (clickpos = pos; col = Red),
     "MouseUp" :> (col = Black)}
   ], {i, 5}, {j, 5}]

Cheers -- Sjoerd

On Apr 4, 3:12 am, "Paul Ellsmore" <paul.ellsm... at> wrote:
> The key point in this problem is that the columns are not equal widths, a=
> in fact are variable width, depending on the particular data displayed. S=
o I
> set ItemSize to automatic, so that each column width is defined by the da=
> The trouble is that MousePosition gives me coordinates that are a linear
> function of the position in the grid, but the columns are not linearly
> spaced in the Grid, so how do I know which column the mouse is in?
> I need one of three things, all three of which are beyond my skills:
> 1) I could get the actual values that ItemSize is set to when Automatic i=
> used. CurrentValue[ItemSize] doesn't work. Anyone got an alternative?
> 2) I could calculate what values ItemSize will be set to by looking at th=
> type and  number of characters in each grid cell, knowing the font size=
> font family, cell margins, frame linewidth etc. But I don't have access t=
> the information needed - how many pixels does a Courier Size 10 "n" take =
> 3) I could use EventHandler in a better way. Currently I wrap it around t=
> whole Grid, but if I could wrap it around a cell, that would work for me.=
> syntax that I have tried works - should I try using GridBox, or is there =
> obvious better idea?
> Nobody got any ideas at all? What kind of language is this, where you can=
> even select a column in a table?
> Cheers,
> Paul.
> -----Original Message-----
> From: Paul Ellsmore [mailto:paul.ellsm... at]
> Sent: 01 April 2009 11:55
> Subject:  selecting a column in a grid
> Hi,
> I have a tricky problem with a graphical user interface. I have a grid of
> data, and I want to be able to MouseClick in the grid to either select a =
> or a column. Using GUIKit, this is trivial, but I want to be able to
> distribute my program using PlayerPro, which won't support GUIKit.
> Selecting a row is straightforward using EventHandler and
> EventHandlerScaled, since I know how many rows there are and they are all
> one line in height. However, the column widths change according to the da=
> since I have set ItemSize to Auto. So is there some way of retrieving the
> actual values used in ItemSize, when Auto is used? I have tried
> CurrentValue[ItemSize] in many variations, but it always fails.
> I could, of course, look at the data that will be in the grid, and comput=
> the widths of each column accordingly, and synthesize the values that
> ItemSize will take. To do that, though, I would need to know what the pix=
> width of a particular text string will be, which varies with font family,
> size etc. Is there an easy way to do this? This is essentially what
> Mathematica does when ItemSize is set to Auto, but I have no idea how to =
> it myself.
> Currently I have EventHandler wrapped around the whole grid. Is it possib=
> to wrap it around each individual cell in a grid? I have tried a few idea=
> but they don't seem to work. The documentation suggests that EventHandler
> can be wrapped around any expression, but that doesn't seem to be the cas=
> or at least the wrapped expression doesn't seem to display properly insid=
> other constructs, such as Grid, Column etc.
> Is there some better approach I could take, rather than using EventHandle=
> All ideas gratefully received.
> Cheers,
> Paul.
> Dr. Paul A. Ellsmore
> Nanion Limited
> Oxford Centre for Innovation
> Mill Street
> Oxford
> United Kingdom
> OX2 0JX
> Tel: +44 (0) 1865 811175
> Fax: +44 (0) 1865 248594

  • Prev by Date: Re: Joust in Mathematica
  • Next by Date: Re: Re: Can nobody help me? Re: selecting a column in a grid
  • Previous by thread: Re: Can nobody help me? Re: selecting a column in a grid
  • Next by thread: Re: Re: Can nobody help me? Re: selecting a column in a grid