Services & Resources / Wolfram Forums / MathGroup Archive
-----

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 smc.vnet.net
  • Subject: [mg98339] Re: [mg98318] Re: Can nobody help me? Re: selecting a column in a grid
  • From: "Paul Ellsmore" <paul.ellsmore at nanion.co.uk>
  • Date: Mon, 6 Apr 2009 05:03:24 -0400 (EDT)
  • References: <gr6c5c$ppo$1@smc.vnet.net> <200904051041.GAA02761@smc.vnet.net>

Hi Albert,

Actually, I have looked at this again, and I have a problem. If you use the
following data to populate the grid 
myData = {{aasdfpppppppppppp, bbbbbbbbb, c}, {dasdf, "", f}, 
       {gasdf, h, i}}

You will see that the cell can only be selected by clicking in the text, not
in any whitespace, and the empty cell cannot be selected at all. This is the
same problem as I have with another suggested solution, which also looked
promising. You mentioned an issue with Spacing, but I don't see why that
matters. Eventhandler is wrapped around each Pane, so mouseclicked should be
recognized anywhere in each Pane. Possibly your ImageMargin setting is
making the Pane only extend as far as the text, does that sound right? I
will try changing those settings, or using a different construct to Pane,
but any advice would be welcome.

Incidentally, just to show my ignorance, I am confused about #1 and #2. I
think #1 means that Pane is applied to each element in the data list at
level 2, but I don't understand what #2[[2]] means, could you explain?

Cheers,

Paul.

-----Original Message-----
From: Albert Retey [mailto:awnl at gmx-topmail.de] 
Sent: 05 April 2009 11:42
To: mathgroup at smc.vnet.net
Subject: [mg98339] [mg98318] Re: Can nobody help me? Re: selecting a column in a grid

Hi,

> 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.

I think using EventHandler for the content of individual cells will work
much better and it works as documented, see below. The problem is that a
cell in a grid is not something that exists as an individual expression
(Item would actually be, but this indeed doesn't work, it looks like
Grid doesn't recognize the Item as such if it is wrapped with EventHandler).

> Is there some better approach I could take, rather than using
EventHandler? 

Would this be close to what you want? Admittedly it is a little hacky,
since one needs to play with the ImageMargins and Spacings options to
get a result that has no blind spots for the mouse clicks and looks
decent. The possibility to wrap Item in Grid with EventHandler would be
nicer, or an option for Item that would allow the handling of events...

Deploy[Grid[
  MapIndexed[
   Item[
     EventHandler[
      Pane[#1, ImageMargins -> {3*{1, 1}, {0, 0}}],
      {"MouseClicked" :> (selectedcolumn = #2[[2]])}],
     Background ->
      Dynamic[If[selectedcolumn == #2[[2]], LightGray, White]]
     ] &,
   {{aasdf, b, c}, {dasdf, e, f}, {gasdf, h, i}},
   {2}
   ],
  Dividers -> All,
  Spacings -> 0.15
  ]]

note that I needed to set a small value for Spacings, otherwise when
clicking in the Spacing-area, the events won't be triggered. Using
Spacings->0 will make the Dividers become invisible which may or may not
be a problem for you. To get back the normal look of the table with
decent margins for the contents of the cells I am using a Pane with
individual ImageMargins options, which you might adopt to your taste. I
was choosing something that is close to the default spacings Grid will
use with no options. Without using Deploy it can happen that instead of
triggering the MouseClick Event you end up selecting some content of the
cell without changing the column selection, so I think usually using
Deploy will be a good choice for an interactive graphical user
interface. Changing the background color for the selected column is just
to demonstrate that it works...

Here is the same thing for selecting cells:

Deploy[Grid[
  MapIndexed[
   Item[
     EventHandler[
      Pane[#1, ImageMargins -> {3*{1, 1}, {0, 0}}],
      {"MouseClicked" :> (selectedcell = #2)}],
     Background -> Dynamic[Switch[selectedcell,
        #2, LightRed,{#2[[1]], _}, LightBlue,
        {_, #2[[2]]}, LightGreen,_, White]]
     ] &,
   {{aasdf, b, c}, {dasdf, e, f}, {gasdf, h, i}},
   {2}
   ],
  Dividers -> All,
  Spacings -> 0.15
  ]]


hth,

albert



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