By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

DataGrid data from two tables

P: n/a
Bob
I have a dataset with two tables. To make it simple, assume they are:
Table_1 with EmployeeID, Name, and ReportsTo fields
Table_2 with ManagerID and Name fields

A data relation is set up between Table_1.ReportsTo and Table_2.ManagerID

In a dataGrid I would like to display the following columns
Table_1.EmployeeID,Table_1.name, and Table_2.Name

Can this be done? If so, how?
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

http://support.microsoft.com/default...b;EN-US;319082

Ken
-------------------------
"Bob" <Bo*@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
I have a dataset with two tables. To make it simple, assume they are:
Table_1 with EmployeeID, Name, and ReportsTo fields
Table_2 with ManagerID and Name fields

A data relation is set up between Table_1.ReportsTo and Table_2.ManagerID

In a dataGrid I would like to display the following columns
Table_1.EmployeeID,Table_1.name, and Table_2.Name

Can this be done? If so, how?
Nov 21 '05 #2

P: n/a
Bob,

I made today a sample, it looks to me very much the same as your question.

\\\ Needs a form with two datagrids, a button and a label
'The first click on the button shows one datagrid
'The second click shows the same info with two datagrid
'To make it nice a lot of other code is needed by instance
datagridtablestyles
'and columnstyles
Private Ds As New DataSet
Private dtCountries As DataTable
Private dtVBLTRegulars As DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
CreateTables()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Static pushed As Integer = 1
Select Case pushed
Case 1
Label1.Text = "Relation One Datagrid"
Dim drel As New DataRelation _
("Regulars", Ds.Tables("Countries").Columns("Country"), _
Ds.Tables("Persons").Columns("Country"))
Ds.Relations.Add(drel)
DataGrid1.DataSource = dtCountries
DataGrid1.Expand(-1)
Case 2
Ds.Relations.RemoveAt(0)
Label1.Text = "Relation two Datatgrids"
Dim drel As New DataRelation _
("Regulars", Ds.Tables("Countries").Columns("Country"), _
Ds.Tables("Persons").Columns("Country"))
Ds.Relations.Add(drel)
DataGrid1.SetDataBinding(Ds, "Countries")
DataGrid2.SetDataBinding(Ds, "Countries.Regulars")
End Select
pushed += 1
End Sub
'This is only needed to show the sample
Private Sub CreateTables()
dtVBLTRegulars = New DataTable("Persons")
dtVBLTRegulars.Columns.Add("Id")
dtVBLTRegulars.Columns.Add("Name")
dtVBLTRegulars.Columns.Add("Country")
For i As Integer = 0 To 7
Dim dr As DataRow = dtVBLTRegulars.NewRow
dr(0) = i.ToString
dtVBLTRegulars.Rows.Add(dr)
Next
dtVBLTRegulars.Rows(0)(1) = "Herfried K. Wagner"
dtVBLTRegulars.Rows(1)(1) = "Ken Tucker"
dtVBLTRegulars.Rows(2)(1) = "CJ Taylor"
dtVBLTRegulars.Rows(3)(1) = "Jay B Harlow"
dtVBLTRegulars.Rows(4)(1) = "Terry Burns"
dtVBLTRegulars.Rows(5)(1) = "Tom Shelton"
dtVBLTRegulars.Rows(6)(1) = "Cor Ligthert"
dtVBLTRegulars.Rows(0)(2) = "EU"
dtVBLTRegulars.Rows(1)(2) = "US"
dtVBLTRegulars.Rows(2)(2) = "US"
dtVBLTRegulars.Rows(3)(2) = "US"
dtVBLTRegulars.Rows(4)(2) = "EU"
dtVBLTRegulars.Rows(5)(2) = "US"
dtVBLTRegulars.Rows(6)(2) = "EU"
dtCountries = New DataTable("Countries")
dtCountries.Columns.Add("Id")
dtCountries.Columns.Add("Country")
For i As Integer = 0 To 1
Dim dr As DataRow = dtCountries.NewRow
dr(0) = i.ToString
dtCountries.Rows.Add(dr)
Next
dtCountries.Rows(0)(1) = "EU"
dtCountries.Rows(1)(1) = "US"
Ds.Tables.Add(dtVBLTRegulars)
Ds.Tables.Add(dtCountries)
End Sub
///

I hope this helps a little bit?

Cor
Nov 21 '05 #3

P: n/a
Bob
That worked greate!! thanks.

"Ken Tucker [MVP]" wrote:
Hi,

http://support.microsoft.com/default...b;EN-US;319082

Ken
-------------------------
"Bob" <Bo*@discussions.microsoft.com> wrote in message
news:1D**********************************@microsof t.com...
I have a dataset with two tables. To make it simple, assume they are:
Table_1 with EmployeeID, Name, and ReportsTo fields
Table_2 with ManagerID and Name fields

A data relation is set up between Table_1.ReportsTo and Table_2.ManagerID

In a dataGrid I would like to display the following columns
Table_1.EmployeeID,Table_1.name, and Table_2.Name

Can this be done? If so, how?

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.