Windows Develop Bookmark and Share   
 index > Windows Forms Designer > cross table
 

cross table

hi..

i have a table in database with the folowing schema

CountryFrom CountryTo ExchangRate

1 2 2.0

1 1 1.0

21 0.5

22 0.03

i want to display them like this in a windows application

1 2

1 1.0 2.0

2 0.5 0.03

Batool  Tuesday, August 21, 2007 12:25 PM

Hi,if you want to show a datatable rotated in a datagrid. Here a sample how that is easy to do. It needs a datagrid on a form.

Code Snippet
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim dt1 As DataTable = CreateTables()
ds.Tables.Add(dt1)
Dim dt2 As New DataTable("Reflection")
ds.Tables.Add(dt2)
For i As Integer = 0 To ds.Tables("Original").Rows.Count - 1
dt2.Columns.Add(i.ToString)
Next
For i As Integer = 0 To ds.Tables("Original").Rows.Count - 1
Dim dr As DataRow = ds.Tables("Reflection").NewRow
For y As Integer = 0 To ds.Tables("Original").Columns.Count - 1
dr(y) = ds.Tables("Original").Rows(y).Item(i)
Next
ds.Tables("Reflection").Rows.Add(dr)
Next
DataGrid1.DataSource = ds.Tables("Reflection")
End Sub

'To have a table to use is one created below
Private Function CreateTables() As DataTable
Dim dt As New DataTable("Original")
dt.Columns.Add("Name")
dt.Columns.Add("State")
dt.Columns.Add("Country")
dt.LoadDataRow(New Object() {"Cor", "Holland", "EU"}, True)
dt.LoadDataRow(New Object() {"Ken", "Florida", "US"}, True)
dt.LoadDataRow(New Object() {"Michael", "New Jersey", "US"}, True)
Return dt
End Function


Hope it helps

Gavin Jin - MSFT  Friday, August 24, 2007 3:37 AM

Hi,if you want to show a datatable rotated in a datagrid. Here a sample how that is easy to do. It needs a datagrid on a form.

Code Snippet
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet
Dim dt1 As DataTable = CreateTables()
ds.Tables.Add(dt1)
Dim dt2 As New DataTable("Reflection")
ds.Tables.Add(dt2)
For i As Integer = 0 To ds.Tables("Original").Rows.Count - 1
dt2.Columns.Add(i.ToString)
Next
For i As Integer = 0 To ds.Tables("Original").Rows.Count - 1
Dim dr As DataRow = ds.Tables("Reflection").NewRow
For y As Integer = 0 To ds.Tables("Original").Columns.Count - 1
dr(y) = ds.Tables("Original").Rows(y).Item(i)
Next
ds.Tables("Reflection").Rows.Add(dr)
Next
DataGrid1.DataSource = ds.Tables("Reflection")
End Sub

'To have a table to use is one created below
Private Function CreateTables() As DataTable
Dim dt As New DataTable("Original")
dt.Columns.Add("Name")
dt.Columns.Add("State")
dt.Columns.Add("Country")
dt.LoadDataRow(New Object() {"Cor", "Holland", "EU"}, True)
dt.LoadDataRow(New Object() {"Ken", "Florida", "US"}, True)
dt.LoadDataRow(New Object() {"Michael", "New Jersey", "US"}, True)
Return dt
End Function


Hope it helps

Gavin Jin - MSFT  Friday, August 24, 2007 3:37 AM

You can use google to search for other answers

Custom Search

More Threads

• designer bugs
• How customize data in datagridview with bound columns?
• List type property, designer update problem
• resize line control
• can mdi form raise double click event?
• Creating new custom ToolStripItems
• Lost my main form in designer
• Query Builder
• find type of grid column
• Form Designer problem with Inheritance Events?