Results 1 to 3 of 3

Thread: Datagrid columns to rows

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    6

    Question Datagrid columns to rows

    Does anyone know how to swap columns with rows in the datagrid control. We're stuch with a particular format in the database that will successfully bring up data in a column which we'd like to 'transpose' into a row!

    Any help would be much appreciated.

    BOZ

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    I have this code which I use to transpose data in my C1 FlexGrid.

    VB Code:
    1. Dim NewGrd As C1FlexGrid = New C1FlexGrid
    2.  
    3.         'set up dimensions
    4.         NewGrd.Rows.Count = grdView.Cols.Count
    5.         NewGrd.Cols.Count = grdView.Rows.Count
    6.         NewGrd.Rows.Fixed = grdView.Cols.Fixed
    7.         NewGrd.Cols.Fixed = grdView.Rows.Fixed
    8.  
    9.         'copy data types, formats, styles, etc.
    10.         'from source columns to dest rows
    11.         Dim i As Integer
    12.         For i = 0 To grdView.Cols.Count - 1
    13.             CopyRowCol(grdView.Cols(i), NewGrd.Rows(i))
    14.         Next
    15.  
    16.         'copy data types, formats, styles, etc
    17.         'from source rows to dest columns
    18.         For i = 0 To grdView.Rows.Count - 1
    19.             CopyRowCol(grdView.Rows(i), NewGrd.Cols(i))
    20.         Next
    21.  
    22.         'transpose data
    23.         Dim r, c As Integer
    24.         For r = 0 To grdView.Rows.Count - 1
    25.             For c = 0 To grdView.Cols.Count - 1
    26.                 NewGrd(c, r) = grdView(r, c)
    27.             Next
    28.         Next
    29.  
    30.         'transfer all data back to original grid
    31.         grdView.DataSource = NewGrd
    32.  
    33.         'and do an autosize
    34.         grdView.AutoSizeCols()

    Hope it helps

    Regards

    Prakash

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    6
    Thanks Prakash

    We used a table in the end (with datarowviews) but the code you've provided is bound to be useful. Thanks very much for your help.

    BOZ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width