# How to add rows to a Grid in front end?

I created a grid g1 with Grid[] and then a separate grid g2. g1 and g2 have same number of columns. How to put the rows of g2 at the end of g1 purely using front-end? I tried to highlight g2, Ctrl+C, and move my curser to various positions in g1 and Ctrl+V. But it always resulted in something not desirable such as the entire g2 being copied into a cell of g1. Any suggestions?

-
So You want to create something like Grid@{gi1, gi2,...,hi1,hi2..} without evaluating anything? (gi1 is first row of g grid). Or do You want it to only look like grid with more rows? –  Kuba Jun 6 '13 at 5:52
something like that: g1 = Grid[{{a, b}, {c, d}}, Frame -> All], g2 = Grid[{{w, x}, {y, z}}, Frame -> All], and then g3=Grid[g1[[1]]~Join~g2[[1]], Frame -> All]? –  Pinguin Dirk Jun 6 '13 at 5:53
@PinguinDirk You're right. –  qazwsx Jun 6 '13 at 6:29
Could you explain why you would want to do something like that using the FrontEnd? I honestly can't find a good use for it. If you'd have to recalculate either of those grids for whatever reason you'd have to manipulate them again in the FrontEnd. Very cumbersome. –  Sjoerd C. de Vries Jun 6 '13 at 22:26

Say you have two Grid:

First place the cursor at the end of the last row:

Then use menu command Add Row (please note the short-cut) to add as many rows as g2 has:

Then copy g2 by dragging from the items (not by select the whole grid or cell!):

Then select all empty rows you just created in g1 and paste:

-
Can you think of any way to do this without creating as many rows as needed manually? I cannot think of a way myself, though I'm hoping one exists. +1 nevertheless. –  Mr.Wizard Jun 6 '13 at 6:09
@Mr.Wizard Thanks. I can't think of one for now, so I would not suggest doing this for large grid.. I'll try it after lunch. Maybe something related to ArrayFlatten.. –  Silvia Jun 6 '13 at 6:16
@Silvia's solution is acceptable for my problem at hand. But in general, having to click once for each new row needed seems rather bad. –  qazwsx Jun 6 '13 at 6:35
@red3y3 To make it feeling (slightly) better, you can press the short-cut instead of click the menu. But still, this is very annoy. –  Silvia Jun 6 '13 at 6:51
@Mr.Wizard I give up.. I think it's too complicated FE programming for a not-so-useful function.. –  Silvia Jun 6 '13 at 9:14

Here is another approach: define a function which can combine two grids preserving the union of their options.

rows = Partition[Range[5 3], 3];
g1 = Grid[rows[[;; 3]], Frame -> All]


g2 = Grid[rows[[4 ;;]], Frame -> All]


JoinGrids[Grid[data1 : {__}, opts1 : ___],
Grid[data2 : {__}, opts2 : ___]] :=
Grid[Join[data1, data2], Sequence @@ Union[{opts1, opts2}]]

JoinGrids[g1, g2]


JoinGrids[g2, g1]


g3 = Grid[rows[[4 ;;, ;; 2]], ItemStyle -> Red]


JoinGrids[g2, g3]


-

Note that the first argument (not including options to Grid) is a 'matrix' (that is a List of Lists in Mathematica).

Given the following example Grids:

Grid[
{{a11, a12, a13},
{a21, a22, a23},
{a31, a32, a33}}
]

Grid[
{{b11, b12, b13},
{b21, b22, b23},
{b31, b32, b33}}
]


(Note that I have spread the syntax for each Grid over several lines using a keyboard return, but each Grid expression should be contained within a single notebook cell; see the brackets off to the right in the Front End.)

You should place a comma after the last 'row' of your first 'matrix', like so:

Grid[
{{a11, a12, a13},
{a21, a22, a23},
{a31, a32, a33} , }
]


Then you copy the rows from your second Grid, being careful not to copy the outer curly braces, like so:

You then paste that copied set of lists ('rows' if you prefer) after the comma in your first Grid:

Grid[
{{a11, a12, a13},
{a21, a22, a23},
{a31, a32, a33},
{b11, b12, b13},
{b21, b22, b23},
{b31, b32, b33}}
]


With a shift-enter to evaluate the cell, you should have a nice Grid,

which you can then decorate with options to Grid.

-
That's not what i meant. I want to operate on the resultant grids, not the defining code. –  qazwsx Jun 6 '13 at 6:31