[vb. net ] Problem with datagrid ???

S

Szaki

Hi,
I have a problem with dataGrid. I have a query to database and it returns me
to datagrid, something like this:

--------------------
| Name | Class |
|BBBBB| 2 |
|aaa | 5 |
--------------------

Can i like make it to format such as
______________________
|Name | BBBBB| aaaaaaa |
|Class | 2 | 5 |
-------------------------------

Please adivce....

Mayby somebody have some code in VB. NET or some example apllication with
code.Please send me ... if you want ofcourse.
My e-mial: (e-mail address removed)

Thanks Luk
 
J

Jim Underwood

I don't think there is a way to have the datagrid reverse rows and collumns,
but what you can do is loop through your dataset and create a new dataset
with the rows and columns reversed.

This function will tkae a datatable and turn the rows into columns and the
columns into rows.

Where dattbl1 is your original datatable...

dim dattbl2 as datatable
dattbl2 = ReverseTable(dattbl1)
DataGrid2.DataSource = dattbl2

Private Function ReverseTable(ByVal dattbl1 As DataTable) As DataTable
Dim i, x As Integer
Dim strDummy As String = ""
Dim datTableOut As New DataTable
Dim dr As DataRow
datTableOut.Columns.Add("ColumnName", strDummy.GetType)
For i = 0 To dattbl1.Rows.Count - 1
datTableOut.Columns.Add("Column" & i, strDummy.GetType)
Next
For i = 0 To dattbl1.Columns.Count - 1
dr = datTableOut.NewRow()
dr("ColumnName") = dattbl1.Columns(i).ColumnName
For x = 0 To dattbl1.Rows.Count - 1
dr("Column" & x) = dattbl1.Rows(x).Item(i)
Next
datTableOut.Rows.Add(dr)
Next
Return datTableOut
End Function
 
M

Michael

Looks like you're after a crosstab query where columns become rows. What's
your sql?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top