Pivot table in DataGrid

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2006
Posts: 14
Reputation: Texpert is an unknown quantity at this point 
Solved Threads: 0
Texpert's Avatar
Texpert Texpert is offline Offline
Newbie Poster

Pivot table in DataGrid

 
0
  #1
Mar 1st, 2006
Hi,

I need help solving this problem.
I have a dataset with four columns col1,col2,col3,col4 and the data could be
col1 col2 col3 col4
=====================================
t1 abc a 1
t1 xyz a 2
t1 mnp b 3
t2 abc 1
t2 kkl 2

I want to create a datagrid which will have, column headings from the col1 data (t1 and t2 as columns) starting from 2nd column in data grid
1st column heading should be blank (like in excel spreadsheet)
and under 1st column in the datagrid, col2 (from source dataset) values should appear as rows
something like this

t1 t2
===========================
abc
xyz
mnp
kkl

that's not it, now remaining two columns col3 and col4 from the source dataset are the attributes of rows, so somehow I need to split each cell under column t1 and t2 and show values of col3 and col4

so far I could get the column headings t1 and t2
by writing separate query for col2 I can even get the first column in datagrid populated but I am clueless how to get two attributes in one cell

any idea ?

thanks in advance
  1. Dim MySQLString As String
  2.  
  3. Dim objParam1 As SqlParameter
  4. Dim MyConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("Conn"))
  5. Dim dest As DataTable
  6.  
  7.  
  8. Try
  9. Session("Current_PackageId") = PackageNameDDL.SelectedItem.Value
  10.  
  11. 'MySQLString = "SELECT DISTINCT Component.Description,Song.SongTitle, "
  12. 'MySQLString = MySQLString + " XREFCompSong.ComponentSeq, XREFCompSong.ComponentSide "
  13. 'MySQLString = MySQLString + " FROM XREFCompSong INNER JOIN"
  14. 'MySQLString = MySQLString + " Song ON XREFCompSong.SongID = Song.PXSongID INNER JOIN"
  15. 'MySQLString = MySQLString + " Component ON XREFCompSong.ComponentID = Component.ComponentID "
  16. 'MySQLString = MySQLString + " WHERE (Component.PackageID = @vPackageId)"
  17.  
  18. MySQLString = "SELECT DISTINCT Component.Description"
  19. MySQLString = MySQLString + " FROM Component "
  20. MySQLString = MySQLString + " WHERE (Component.PackageID = @vPackageId)"
  21.  
  22. Dim MySqldataAdapter As SqlDataAdapter = New SqlDataAdapter(MySQLString, MyConn)
  23. Dim MyDataSet As DataSet = New DataSet
  24.  
  25. objParam1 = MySqldataAdapter.SelectCommand.Parameters.Add("@vPackageId", SqlDbType.Int)
  26. objParam1.Value = PackageNameDDL.SelectedItem.Value
  27.  
  28. If MyConn.State = ConnectionState.Closed Then
  29. MyConn.Open()
  30. End If
  31.  
  32. MySqldataAdapter.Fill(MyDataSet)
  33.  
  34. dest = New DataTable("PivotTable")
  35. dest.Columns.Add(" ")
  36.  
  37. Dim r As DataRow
  38.  
  39. For Each r In MyDataSet.Tables(0).Rows
  40. dest.Columns.Add(r(0))
  41. Next
  42.  
  43. DataGrid1.DataSource = dest
  44. DataGrid1.DataBind()
  45.  
  46. MyConn.Dispose()
  47. MyConn.Close()
  48. Catch ex As Exception
  49. System.Diagnostics.Trace.WriteLine("[ShowBtnClick] Exception " & ex.Message)
  50. Finally
  51. MyConn.Close()
  52. End Try
Notice that I've commented out first query, because with that query I get error while creating columns that "column t1 is already in the dataset", since t1 repeates in the query result.

Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 4
Reputation: luciano_sunny is an unknown quantity at this point 
Solved Threads: 0
luciano_sunny luciano_sunny is offline Offline
Newbie Poster

Re: Pivot table in DataGrid

 
0
  #2
Feb 26th, 2008
Hi there did you get any reply from anywhere for this problem of yours because i am also stuck with almost same kind of thing.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1
Reputation: JakeDB is an unknown quantity at this point 
Solved Threads: 0
JakeDB JakeDB is offline Offline
Newbie Poster

Re: Pivot table in DataGrid

 
0
  #3
Jul 19th, 2008
Sound like you need a real pivot table gird with some customization capabilities. There are a few of them on the market but usually quite pricy. You can try the VIBlend SuperGridView. http://www.viblend.com. Not too expensive and does a great job.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC