Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Please Help me datagridview rearange

rapsoyso09

Novice
Advanced Member
Messages
29
Reaction score
0
Points
26
Hello po sa inyu mga ka Symb.
I'm using VB.net 2010

Please help me po sa datagridview.
ito po ang codes ko:

Private Function reArrangeDatatable1(ByVal dt As DataTable) As DataTable
Dim newTable As New DataTable
newTable.Columns.AddRange({New DataColumn(dt.Columns(12).ColumnName)}) 'Converting column(database) to row(datagridview1)
For x As Integer = 0 To dt.Rows.Count - 1
newTable.Rows.Add(dt.Rows(x).Item(12)) ' Farm - Column Header
newTable.Rows.Add(dt.Rows(x).Item(0)) ' date
newTable.Rows.Add(dt.Rows(x).Item(1)) ' wof7
newTable.Rows.Add(dt.Rows(x).Item(2)) ' wof8
newTable.Rows.Add(dt.Rows(x).Item(3)) ' wof9
newTable.Rows.Add(dt.Rows(x).Item(4)) ' wof10
newTable.Rows.Add(dt.Rows(x).Item(5)) ' wof11
newTable.Rows.Add(dt.Rows(x).Item(6)) ' wof12
newTable.Rows.Add(dt.Rows(x).Item(7)) ' wof13
newTable.Rows.Add(dt.Rows(x).Item(8)) ' wof14
newTable.Rows.Add(dt.Rows(x).Item(9)) ' wof15
newTable.Rows.Add(dt.Rows(x).Item(10)) ' wof16
newTable.Rows.Add(dt.Rows(x).Item(11)) ' total
Next
Return newTable
end sub

Private Function reArrangeDatatable2(ByVal dt As DataTable) As DataTable ' Converting column(database) to row(datagridview1)
Dim newTable As New DataTable
newTable.Columns.AddRange({New DataColumn(dt.Columns(12).ColumnName)})
For x As Integer = 0 To dt.Rows.Count - 1
newTable.Rows.Add(dt.Rows(x).Item(12)) ' Farm - Column Header
newTable.Rows.Add(dt.Rows(x).Item(0)) ' date
newTable.Rows.Add(dt.Rows(x).Item(1)) ' wof7
newTable.Rows.Add(dt.Rows(x).Item(2)) ' wof8
newTable.Rows.Add(dt.Rows(x).Item(3)) ' wof9
newTable.Rows.Add(dt.Rows(x).Item(4)) ' wof10
newTable.Rows.Add(dt.Rows(x).Item(5)) ' wof11
newTable.Rows.Add(dt.Rows(x).Item(6)) ' wof12
newTable.Rows.Add(dt.Rows(x).Item(7)) ' wof13
newTable.Rows.Add(dt.Rows(x).Item(8)) ' wof14
newTable.Rows.Add(dt.Rows(x).Item(9)) ' wof15
newTable.Rows.Add(dt.Rows(x).Item(10)) ' wof16
newTable.Rows.Add(dt.Rows(x).Item(11)) ' total
Next
Return newTable
end sub

Private Sub farm1_farm2()

'name of my datagridview is datagridview1

Dim sSQLText1 As String = "SELECT top 1 * table1"
Using dbConnection1 As New SqlConnection(conn_string)
dbConnection1.Open()
Dim dbCommand1 As New SqlCommand(sSQLText1, dbConnection1)
Dim dsData1 As New DataSet
Dim dbAdapter1 As New SqlDataAdapter(sSQLText1, dbConnection1)
dbAdapter1.Fill(dsData1)
datagridview1.DataSource = reArrangeDatatable1(dsData1.Tables(0))
dbConnection1.Close()
End Using

Dim sSQLText2 As String = "SELECT top 1 * table2"
Using dbConnection2 As New SqlConnection(conn_string)
dbConnection2.Open()
Dim dbCommand2 As New SqlCommand(sSQLText2, dbConnection2)
Dim dsData2 As New DataSet
Dim dbAdapter2 As New SqlDataAdapter(sSQLText2, dbConnection2)
dbAdapter2.Fill(dsData1)
datagridview1.DataSource = reArrangeDatatable2(dsData2.Tables(0))
dbConnection2.Close()
End Using
end sub

Private Sub column_header()
datagridview1.ColumnCount = 1
datagridview1.Columns(0).Name = "PARTICULAR"
End Sub


Private Sub row_header()
' dview_daily_prod.RowCount = 13
datagridview1.Rows(0).Cells(0).Value = "date"
datagridview1.Rows(1).Cells(0).Value = "wof 7"
datagridview1.Rows(2).Cells(0).Value = "wof 8"
datagridview1.Rows(3).Cells(0).Value = "wof 9"
datagridview1.Rows(4).Cells(0).Value = "wof 10"
datagridview1.Rows(5).Cells(0).Value = "wof 11"
datagridview1.Rows(7).Cells(0).Value = "wof 12"
datagridview1.Rows(8).Cells(0).Value = "wof 13"
datagridview1.Rows(9).Cells(0).Value = "wof 14"
datagridview1.Rows(10).Cells(0).Value = "wof 15"
datagridview1.Rows(11).Cells(0).Value = "wof 16"
datagridview1.Rows(12).Cells(0).Value = "total"
end sub

Private Sub menu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
column_header()
farm1_farm2()
row_header()
End Sub

table name
Table 1 date Wof 7 Wof 8 Wof 9 Wof 10 Wof 11 Wof 12 Wof 13 Wof 14 Wof 15 Wof 16 total Farm 1
Table 2 date Wof 7 Wof 8 Wof 9 Wof 10 Wof 11 Wof 12 Wof 13 Wof 14 Wof 15 Wof 16 total Farm 2

Ito po output
PARTICULAR Farm 2
date
Wof 7
Wof 8
Wof 9
Wof 10
Wof 11
Wof 12
Wof 13
Wof 14
Wof 15
Wof 16
Total



Ganito dapat output
Particular Farm 1 Farm 2
date
Wof 7
Wof 8
Wof 9
Wof 10
Wof 11
Wof 12
Wof 13
Wof 14
Wof 15
Wof 16
Total


MARAMING SALAMAT PO.
SANA AY MATULUNGAN NYU AKO..
 
Last edited:
Back
Top Bottom