Rotate DataGridView

R

Rainer Queck

Hello NG,

Is there a way to "rotate" a DataGridView?
I would like to assigne the DataRows of a DataTable to Columns, so that all
table columns show up in the DataGridRows instead.

example:

the table holds rows of:
int No
string Name
int Age

this would show up currently as:

No Name Age
1 Frank 25
2 Klaus 43
3 Jeff 34

I would like to display this information in a DataGridView in the following
way
No 1 2 3
Name Frank Klaus Jeff
Age 25 43 34

Is there a way to achieve this?

Regards
Rainer
 
H

Hongye Sun [MSFT]

Hi Rainer,

I am redirected from another post from you.

This is a very interesting question. If you are using DataTable type to
hold the data, please use the following function to build another rotated
data table:
---------------------------------------------
public DataTable RotateTable(DataTable dt)
{
DataTable table = new DataTable();
for (int i = 0; i <= dt.Rows.Count; i++)
{
table.Columns.Add(Convert.ToString(i));
}
DataRow r = null;
for (int k = 0; k < dt.Columns.Count; k++)
{
r = table.NewRow();
r[0] = dt.Columns[k].ToString();
for (int j = 1; j <= dt.Rows.Count; j++)
r[j] = dt.Rows[j - 1][k];
table.Rows.Add(r);
}

return table;
}
---------------------------------------------
In your example, the rotated table will look like:
1 2 3 4
No 1 2 3
Name Frank Klaus Jeff
Age 25 43 34

Set DataGridView's ColumnHeadersVisible to false, so that the numeric
column will not display.

Please let me know if it works for you. Thanks.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
 
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
H

Hongye Sun [MSFT]

Sorry that one mistake in my previous post. The rotated table should be:
0 1 2 3
No 1 2 3
Name Frank Klaus Jeff
Age 25 43 34


Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 
H

Hongye Sun [MSFT]

Hi Rainer,

I have not heard from you for many days. I am writing to follow up this
issue and check if the issue has been well resolved. In my last reply, I
have provided a way for you to rotate datatable in a function. Does it work
for this issue? Please let us know if you need any further help on this and
we will be more than happy to be of assistance.

Have a great holiday.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top