MathGroup Archive 2009

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

Search the Archive

RE: selecting a column in a grid

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98252] RE: selecting a column in a grid
  • From: "Paul Ellsmore" <paul.ellsmore at nanion.co.uk>
  • Date: Fri, 3 Apr 2009 04:39:54 -0500 (EST)
  • References: <gr0gc4$92c$1@smc.vnet.net> <49D46EA9.1000202@metrohm.com>

Thanks Daniel, but I couldn't get your code to do anything (not even give an
error message. I'm a novice, and don't understand your syntax - what is the
# & doing inside the Print statement for example - so haven't been able to
debug it.

In any case, I'm fairly sure your code doesn't help me. As I said, choosing
a row with EventHandler and EventHandlerScaled is trivial, because the row
position is linearly dependent on the mouse position in the grid. But that
is not the case with the columns, since some of my columns can be anything
from one to 100 characters wide.

Cheers anyway,

Paul.

Dimensions[] just gives me the size of the grid in elements, what I need is
the actual values of ItemSize as determined by Mathematica when one of the
ItemSize options is set to Auto. 

-----Original Message-----
From: dh [mailto:dh at metrohm.com] 
Sent: 02 April 2009 08:52
To: Paul Ellsmore
Subject: [mg98252] Re: selecting a column in a grid

Hi Paul,
you may e.g. use EventHaldler with "MouseClicked" and 
MousePosition["EventHandlerScaled"]. This gives you scaled coordinates. 
The run from lower left to upper right and you have to fiddel a bit with 
them to get row and colum. Here is an example that prints row and column:
gr = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {7, 8, 9}, {7, 8, 9}};
myGrid[gr_] := EventHandler[
   Grid[gr]
   , "MouseClicked" :> (Print[{1, 2} + {0, 1} # &[Dimensions[gr]] +
       Round[{0.5, -1.5} # & [
         Dimensions[gr] MousePosition["EventHandlerScaled"]]]])
   ]

Daniel

Paul Ellsmore wrote:
> 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
row
> 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
data,
> 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 compute
> 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
pixel
> 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
do
> it myself.
> 
>  
> 
> Currently I have EventHandler wrapped around the whole grid. Is it
possible
> to wrap it around each individual cell in a grid? I have tried a few
ideas,
> 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
case,
> or at least the wrapped expression doesn't seem to display properly inside
> other constructs, such as Grid, Column etc.
> 
>  
> 
> Is there some better approach I could take, rather than using
EventHandler? 
> 
>  
> 
> 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: Footnotes, Endnotes in Mathematica
  • Next by Date: Re: selecting a column in a grid
  • Previous by thread: selecting a column in a grid
  • Next by thread: Re: selecting a column in a grid