Rows as Columns

Apr 27, 2009 at 2:02 PM
Is it possible to flip rows and columns?

So for example, if I currently have 20 fields and 3 records, I'd see them as 3 rows and 20 columns, where each of the field names appears in the column header cell.

I'd like to swap them so that I see 20 rows, 3 columns, with field names appearing the row header cell.


Apr 28, 2009 at 5:18 PM
You can just recreate the grid and flip everything.
May 19, 2009 at 1:17 PM

Will this work if one of my columns contains checkboxes, one contains just text, and one contains ints?

May 19, 2009 at 4:20 PM

Could you be more specific? I have a feeling, that we might be talking about different things

May 19, 2009 at 9:45 PM

I actually have a large DataTable, with a variety of column types (strings, ints, floats, bools, etc).

I use SourceGrid to display the data in the usual way - each row in the DataTable becomes a row in the SourceGrid; each field in the DataTable becomes a column in the SourceGrid.

So far so good.

Now, unfortunately, I have so many fields in my DataTable that I can't see all the columns of the SourceGrid on screen at once.

So what I want to do is transpose or rotate the SourceGrid so that the rows of the DataTable appear vertically and each field/column appears horizontally.

In the normal grid, my columns have the same types as the column types in the DataTable (string, int, float, bool, etc).  The string, int and float column cells can all be edited by typing into the cells, and the bool column cells are all checkboxes (as expected).

Instead I would like the String "column" to be the top row of the SourceGrid, the int "column" to be the next row of the source grid, the float column to be the thirds row of the grid, and the bool column to be the 4th row in the grid.  So if I had 20 records in the DataTable, I'd see 20 columns in the SourceGrid.  Each column would contain 1 string, 1 int, 1 float (all text editable cells) and 1 bool (a checkbox cell).

It'd probably be easier to draw than describe, but I did my best!

May 25, 2009 at 8:06 AM

Ok, i hope i understood now where is the problem.

Probably, you are using DataGrid to display data, is that right?      With DataGrid you can not "rotate" the grid, but you can achieve this manually by using Grid and constructing cells yourself.

Of course, if you have a large DataTable, as you already say, you might have performance problems. In that case there are these ways:

1. either somehow limit your datatable so you have decent performance,

2. reconstruct your datatable before passing it to DataGrid

3. or modify DataGrid component to supporting swapping rows with columns, but this is somewhat tricky to achieve, since DataTable support sorting out of the box, and thus this behaviour should be changed as well. A lot of work, actually.

I would personally go with second option