Results 1 to 5 of 5

Thread: [RESOLVED] [2005] rows like columns and columns like rows in dgw?

  1. #1

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Resolved [RESOLVED] [2005] rows like columns and columns like rows in dgw?

    Hi,
    I know that the title is not good but I didnt find a better one. My question is, is it possible to show datagridview columns as rows.
    normally it is like this:
    Age Name
    34 Jack
    23 Linda
    ... ...

    But I dont have enough height to display long 2 columns and I thought maybe a formation like this would be better:

    Age 34 32
    Name Jack Linda

    These values are only examples. Is it possible to tell dgw to show these values so?

    Thanks for any help... I cant find anything about this in google...
    Dim Me As Coder

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: [2005] rows like columns and columns like rows in dgw?

    Try using a FormView control. This will only retrieve one DataRow at a time, but it binds each value to an object in the FormView, which you can format as you please.

  3. #3

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] rows like columns and columns like rows in dgw?

    there is only a formview which is a webcontrol acn I use it in my forms? it is added as a .net component but I cant see it in my toolbox...
    Dim Me As Coder

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] rows like columns and columns like rows in dgw?

    If your datagridview is just for displaying records (readonly), you can create a rotated datatable from the original datatable and bind that to your DGV and be done with it. However, if you also allow editing on the DGV then you must remember to rorate the binded datable back every time you do an update to your database. I've never done it but theretically it should work.

  5. #5

    Thread Starter
    Addicted Member Genom's Avatar
    Join Date
    May 2006
    Posts
    186

    Re: [2005] rows like columns and columns like rows in dgw?

    it is programmatically editable user cant edit that. There are some buttons which edits the data. So I think it will work. But I cant see the values on my second datagridview. Because of the structure of my application it is better to take all values first to a datagrdiview and then rotate and put it toanother one. So I have written a sub for this:

    vb Code:
    1. Public Sub Rotate(ByVal Source As DataGridView, ByVal Destination As DataGridView)
    2.         Dim i As Integer
    3.  
    4.         For i = 0 To Source.Rows.Count - 1
    5.             Destination.Columns.Add(i, "")
    6.         Next
    7.  
    8.         For i = 0 To Source.Columns.Count - 1
    9.             Destination.Rows.Add()
    10.         Next
    11.  
    12.         For i = 0 To Source.Rows.Count - 1
    13.             Destination.Rows(0).Cells(i).Value = Source.Rows(i).Cells(1).FormattedValue
    14.             Destination.Rows(1).Cells(i).Value = Source.Rows(i).Cells(0).FormattedValue
    15.         Next
    16.  
    17.     End Sub

    the problem is that the second DGV is empty. it has columns and rows as needed but cells dont have values. I think there is something wrong with 3rd for statement.

    Edit:
    Ok I did it. I have changed the virtual mode to false and it worked Thanks guys...
    Last edited by Genom; Aug 2nd, 2007 at 09:08 AM.
    Dim Me As Coder

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