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.
In other words: “First Column of the Table should have Columns name and 2nd Column should have its corresponding values”
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:
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With