Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a DataGridView with vertical Columns

In my Winform C# application I have a DataGridView that bound with DataTable and have many records. I want to display details of the selected row (of DataGridView ) in the following Format (see Image).What Control or (Trick) should I use to achieve this.

enter image description here

In other words: “First Column of the Table should have Columns name and 2nd Column should have its corresponding values”

like image 972
prograshid Avatar asked Jan 23 '14 22:01

prograshid


2 Answers

Typically, I wouldn't do this in a DataGridView, its really intended to display multiple records and you only want to display one record at a time. I can suggest two alternate ways of dealing with this:

The typical approach if you know the fields to be displayed ahead of time would be to lay out a set of individual value displaying labels and other simple controls at design time. This has the following advantages:

  • The position of things is more flexible
  • The type of control used for each individual field can be customized. For example, a booean value might display with a check box, rather than with text.
  • The labels preceding the value can be localized into the users language. Even if not an international application, its sometimes useful to display labels that are different from the database schema names of the columns.

If you don't know the fields to be displayed at design time, or don't want to bother laying them out, use a PropertyGrid control instead of a DataGridView. I've never actually tried this with a DataTable as a data source, but it looks like there is a well developed answer for that at C#/winforms: how to best bind a propertygrid and a System.Data.DataRow

like image 169
Burt_Harris Avatar answered Nov 15 '22 03:11

Burt_Harris


I hope you 'll try to use PIVOT in sql to make your dataset looks like the above result. Instead of that you can pivot (switch rows and columns) in your DataSet and bind that dataset to your grid. See below link,It'll help you..

http://codemaverick.blogspot.com/2008/02/transpose-datagrid-or-gridview-by.html

like image 26
tarzanbappa Avatar answered Nov 15 '22 03:11

tarzanbappa