Home › Forums › WinForms controls › Xceed Grid for WinForms › Master-Detail-Detail Repeating rows
-
AuthorPosts
-
#15709 |
I am attempting to display a Master->Detail->Subdetail grid. I am getting a problem whereby the SubDetail rows are repeating for each Detail row. I am sure I am doing something wrong but cannot see what. This is the code that I am using to populate the dataset and grid (in my proof of concept code).
‘ create the dataset
ds = New DataSet(“Master-Detail-SubDetail”)‘ add the master table
ds.Tables.Add(“Master”)
Dim colMasterID As New DataColumn(“MasterID”, GetType(Integer))
colMasterID.Unique = True
ds.Tables(“Master”).Columns.Add(colMasterID)
ds.Tables(“Master”).Columns.Add(“Description”, GetType(String))
‘ Made no difference
‘ ds.Tables(“Master”).PrimaryKey = New DataColumn() {ds.Tables(“Master”).Columns(“MasterID”)}
‘ colMasterID.AutoIncrement = True
‘ colMasterID.AutoIncrementSeed = 1
‘ colMasterID.AutoIncrementStep = 1‘ add the detail table
ds.Tables.Add(“Detail”)
Dim colDetailID As New DataColumn(“DetailID”, GetType(Integer))
colDetailID.Unique = True
ds.Tables(“Detail”).Columns.Add(colDetailID)
ds.Tables(“Detail”).Columns.Add(“MasterID”, GetType(Integer))
ds.Tables(“Detail”).Columns.Add(“Description”, GetType(String))
‘ Made no difference
‘ ds.Tables(“Detail”).PrimaryKey = New DataColumn() {ds.Tables(“Detail”).Columns(“DetailID”)}
‘ colDetailID.AutoIncrement = True
‘ colDetailID.AutoIncrementSeed = 1
‘ colDetailID.AutoIncrementStep = 1‘ add the subdetail table
ds.Tables.Add(“SubDetail”)
Dim colSubDetailID As New DataColumn(“SubDetailID”, GetType(Integer))
colSubDetailID.Unique = True
ds.Tables(“SubDetail”).Columns.Add(colSubDetailID)
ds.Tables(“SubDetail”).Columns.Add(“DetailID”, GetType(Integer))
ds.Tables(“SubDetail”).Columns.Add(“Description”, GetType(String))
‘ Made no difference
‘ ds.Tables(“SubDetail”).PrimaryKey = New DataColumn() {ds.Tables(“SubDetail”).Columns(“SubDetailID”)}
‘ colSubDetailID.AutoIncrement = True
‘ colSubDetailID.AutoIncrementSeed = 1
‘ colSubDetailID.AutoIncrementStep = 1‘ set up the relationship between Master -> Detail tables
Dim relMaster2Detail As New DataRelation(“Master->Detail”, _
ds.Tables(“Master”).Columns(“MasterID”), _
ds.Tables(“Detail”).Columns(“MasterID”))
relMaster2Detail.Nested = True
ds.Relations.Add(relMaster2Detail)‘ set up the relationship between Detail -> SubDetail tables
Dim relDetail2SubDetail As New DataRelation(“Detail->SubDetail”, _
ds.Tables(“Detail”).Columns(“DetailID”), _
ds.Tables(“SubDetail”).Columns(“DetailID”))
relDetail2SubDetail.Nested = True
ds.Relations.Add(relDetail2SubDetail)‘ add some records for our viewing pleasure
Dim intMasterID As Integer = 1
Dim intDetailID As Integer = 1
Dim intSubDetailID As Integer = 1For intMasterRow As Integer = 1 To 2
ds.Tables(“Master”).Rows.Add(New Object() {intMasterID, String.Format(“Master Row {0}”, intMasterID)})For intDetailRow As Integer = 1 To 3
ds.Tables(“Detail”).Rows.Add(New Object() {intDetailID, intMasterID, String.Format(“Master Row {0} Detail Row {1}”, intMasterID, intDetailID)})For intSubDetailRow As Integer = 1 To 4
ds.Tables(“SubDetail”).Rows.Add(New Object() {intSubDetailID, intDetailID, String.Format(“Master Row {0} Detail Row {1} SubDetail Row {2}”, intMasterID, intDetailID, intSubDetailID)})
intSubDetailID += 1
NextintDetailID += 1
NextintMasterID += 1
Next
ds.Tables(“Master”).AcceptChanges()
ds.Tables(“Detail”).AcceptChanges()
ds.Tables(“SubDetail”).AcceptChanges()‘ save as XML so I can see what’s been entered into the dataset
IO.File.WriteAllText(“c:\test.xml”, ds.GetXml())‘ set up the grid
grdMaster.BeginInit()grdMaster.SynchronizeDetailGrids = True
‘ set up the grid for table: Master
grdMaster.SetDataBinding(ds.Tables(“Master”), “”)
grdMaster.Columns(“Description”).Width = 400‘ set up a detail grid for table: Detail
Dim grdDetail As New Xceed.Grid.DetailGrid
grdDetail.SetDataBinding(ds.Tables(“Master”), “Master->Detail”)
grdDetail.HeaderRows.Add(New Xceed.Grid.ColumnManagerRow)‘ set up a detail grid for table: SubDetail
Dim grdSubDetail As New Xceed.Grid.DetailGrid
grdSubDetail.SetDataBinding(ds.Tables(“Detail”), “Detail->SubDetail”)
grdSubDetail.HeaderRows.Add(New Xceed.Grid.ColumnManagerRow)‘ add and update the detail grids
grdMaster.DetailGridTemplates.Add(grdDetail)
grdDetail.DetailGridTemplates.Add(grdSubDetail)
grdMaster.UpdateDetailGrids()grdMaster.EndInit()
Many thanks for any assistance.
David.Imported from legacy forums. Posted by David (had 4200 views)
I recommend checking this previous thread that shows a lot more on Master-Detail:
http://forums.xceed.com/forums/ShowPost.aspx?PostID=8368
Imported from legacy forums. Posted by CharlesB (had 285 views)
Was your problem ever resolved? I am having similar symptoms and would like to know what worked for you.
Appreciate all pointers.
Imported from legacy forums. Posted by Anshu (had 505 views)
I am also facing this problems, that the SubDetail rows are repeating for each Detail row. When I insert one SubDetail row it inserts into every detail element.
Is there any workaround for this problem?
Imported from legacy forums. Posted by Pavel (had 420 views)
I’ve found an error in my code.
You have to use such string for DataMember for SubDetail:
“MasterTable.Relation1.Relation2”,
but not
“DetailTable.Relation2”.If you use “DetailTable.Relation2” for SubDetail DataMember you will get the same problem as specified above.
Imported from legacy forums. Posted by Pavel (had 3639 views)
Do you have a working solution for this, i tried the same in setting the relation but not able to get it.
It fetches me error
5 – Child list for field ScreenGriding cannot be created.
Source : System.Windows.Forms
Imported from legacy forums. Posted by Credits (had 423 views)
Have you looked at the post suggested above?
http://xceed.com/CS/forums/thread/2916.aspx
Imported from legacy forums. Posted by André (had 1130 views)
-
AuthorPosts
- You must be logged in to reply to this topic.