473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to add a column in a master detail realtionship using datagrid controls?

I built a form that displays a master-detail relation ship, now i need to
add a column to the datagrid displaying the master data, this column
corresponds to the text name of a column stored in the master table as an
integer (the foreign key, i need to display the text name of the foreign key
stored in the third table).

Do i have to create another datatable in the dataset im using that includes
all the information I need?
Change the Sql statement to include that information in the master table?
....

what is the best way to do it? I would prefer that my dataset represents the
database structure table by table.

Nov 22 '05 #1
1 1583
Juan,

I made a sample for the language.vb newsgroup for that, I changed it a
little bit, and maybe it fits your problem

\\\
'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 dtVBReg 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
dtVBReg.Columns.Add("MyNewColumn", GetType(System.Boolean),
"Country = 'US'")
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)
DataGrid1.ReadOnly = True
Case 2
dtVBReg.Columns.Add("MyNewColumn", GetType(System.Boolean),
"Country = 'US'")
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")
DataGrid1.AllowNavigation = False
DataGrid2.AllowNavigation = False
DataGrid2.ReadOnly = True

End Select
pushed += 1
End Sub
Private Sub CreateTables()
dtVBreg = New DataTable("Persons")
dtVBreg.Columns.Add("Name")
dtVBreg.Columns.Add("Country")
For i As Integer = 0 To 7
dtVBreg.Rows.Add(dtVBreg.NewRow)
Next
dtVBreg.Rows(0).ItemArray = New Object() _
{"Herfried K. Wagner", "EU"}
dtVBreg.Rows(1).ItemArray = New Object() _
{"Ken Tucker", "US"}
dtVBreg.Rows(2).ItemArray = New Object() _
{"CJ Taylor", "US"}
dtVBreg.Rows(3).ItemArray = New Object() _
{"Jay B Harlow", "US"}
dtVBreg.Rows(4).ItemArray = New Object() _
{"Terry Burns", "EU"}
dtVBreg.Rows(5).ItemArray = New Object() _
{"Tom Shelton", "US"}
dtVBreg.Rows(6).ItemArray = New Object() _
{"Cor Ligthert", "EU"}
dtCountries = New DataTable("Countries")
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)(0) = "EU"
dtCountries.Rows(1)(0) = "US"
ds.Tables.Add(dtVBreg)
ds.Tables.Add(dtCountries)
End Sub
////

I hope this helps?

Cor

"Juan" <ju*****************@ANTISPAMhotmail.com>
I built a form that displays a master-detail relation ship, now i need to
add a column to the datagrid displaying the master data, this column
corresponds to the text name of a column stored in the master table as an
integer (the foreign key, i need to display the text name of the foreign
key
stored in the third table).

Do i have to create another datatable in the dataset im using that
includes
all the information I need?
Change the Sql statement to include that information in the master table?
...

what is the best way to do it? I would prefer that my dataset represents
the
database structure table by table.


Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Juan | last post by:
I built a form that displays a master-detail relation ship, now i need to add a column to the datagrid displaying the master data, this column corresponds to the text name of a column stored in the...
0
by: Juan | last post by:
I built a form that displays a master-detail relation ship, now i need to add a column to the datagrid displaying the master data, this column corresponds to the text name of a column stored in the...
2
by: Marcel | last post by:
Hi, I'm new to VS and ASP.NET and have a question about master/detail datagrids. I have a master datagrid filled with data via a component that contains a SQL adapter. Now I would like to fill...
6
by: Beren | last post by:
Hi all I'm almost braindead on this one, but how can I create a master/detail datagrid in this format : CatA subcatA1 subcatA2 subcatA3
3
by: jason | last post by:
I'll try to explain in detail what it is I'm struggling with. I created a SQL database with one table called CallSheet which contains the following columns: Caller ID: <--Primary Key, auto...
0
by: hlam | last post by:
Help - Calculating the total of a column in a data grid -- when data grid is part of Master-Detail set-up I have setup a Master-Detail form using Visual Studio.Net. A ListBox is the (Master)...
1
by: solex | last post by:
Hello, I am trying (unsuccessfully) to display a Master-Detail-Detail records. The problem comes in the second detail grid. The first detail grid is displaying correctly but it is not...
1
by: Larry Woods | last post by:
I have a combobox that is populated with a list of names. When a name is selected I want to populate a datagrid with name information. I have my master-detail defined in my dataset and it works...
8
by: Doug Bell | last post by:
Hi, I need to create a function that will return the number of columns in a passed reference to a DataView. I can find the number of columns in its underlying Data table but have not been...
1
by: Gary200 | last post by:
Hello All, I bind two datagrids in a master-detail relationship successfully. What I want is to set allowNew and allowDelete disabled in both datagrid using dataview. The code like this: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.