Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Can I assign a style to a GridBox row?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63393] Can I assign a style to a GridBox row?
  • From: "Steven T. Hatton" <hattons at globalsymmetry.com>
  • Date: Thu, 29 Dec 2005 02:57:25 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I want to alternate between a lightgray and white background in subsequent
rows of a GridBox[] table representing data I have processed.  Is there a
way to assign a style to a row?  

This is what I currently have:

MakeRow[{country_, samples_, percent_}] :=
  {
    Cell[TextData[{country, " "}]],
    Cell[TextData[{samples, " "}]],
    Cell[TextData[{ToString[PaddedForm[percent, {5, 2}]], " "}]]
    }

MakeTableBody[tbl_] :=
  CellPrint[
    Cell[
      BoxData[
        GridBox[Table[
            MakeRow[ tbl[[i]] ]
            , {i, 1, Length[tbl]}]
          , ColumnAlignments -> {Left, Right}
          ]
        ]
      ]
    ]

And here is some sample data:

{{Unknown Origin, 58, 100.}, {Sweden, 81, 1.23457}, {Scotland, 1826, 
    1.09529}, {Great Britain, 221, 0.904977}, {Netherlands, 117, 
    0.854701}, {Ireland, 1915, 0.626632}, {Spain, 165, 0.606061}, {Germany, 
    1064, 0.56391}, {England, 4349, 0.436882}, {France, 271, 
    0.369004}, {United Kingdom, 889, 0.224972}}

I've tried wrapping the result of MakeRow with a StyleBox, but I get errors
saying "An unknown box name (List) was sent as the BoxForm for the
expression. Check the format rules for the expression."

This is the code that caused that:

MakeTableBody[tbl_] := 
  Module[{bgEven = RGBColor[0.8, 0.8, 1.0], bgOdd = RGBColor[1.0, 0.8,
0.8]},
    CellPrint[
      Cell[
        BoxData[
          GridBox[Table[
              StyleBox[
                MakeRow[ tbl[[i]] ]
                , Background -> If[OddQ[i], bgOdd, bgEven]
                ]
              , {i, 1, Length[tbl]}]
            , ColumnAlignments -> {Left, Right, Left}
            ]
          ]
        ]
      ]
    ]

How do I fix this?

-- 
The Mathematica Wiki: http://www.mathematica-users.org/
Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html
Math for the WWW: http://www.w3.org/Math/


  • Prev by Date: Re: Re: Taking either a sequence or a list
  • Next by Date: Re: Re: Making a new definition of Equal work with lists as well
  • Previous by thread: Re: Piecewise Integration Woes
  • Next by thread: Re: Can I assign a style to a GridBox row?