Home Forums WinForms controls Xceed Grid for WinForms Building an unbound hierarchical master/detail grid

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14628 |

    Hello.

    I want to know if its possible to populate a MASTER/DETAIL grid without using a eventhandler as used in the doc. sample.

    In case of being possible, how can i populate the MASTER/Detail sample included in your DOC.
    (You can modify the next sample)

    Thanks Jacob.

    Main()

    ‘ This call is required by the Windows Form Designer.
    InitializeComponent()

    Dim grid As New GridControl()
    grid.BeginInit() ‘ EndInit will be called later

    ‘ Add the grid to the form
    Me.Controls.Add(grid)
    grid.Dock = DockStyle.Fill

    grid.Columns.Add(New Column(“FirstName”, GetType(String)))
    grid.Columns.Add(New Column(“LastName”, GetType(String)))
    grid.Columns.Add(New Column(“FamilyID”, GetType(Integer)))
    grid.Columns.Add(New Column(“Occupation”, GetType(String)))

    Dim row1 As Xceed.Grid.DataRow = grid.DataRows.AddNew()
    row1.Cells(“FirstName”).Value = “Peter”
    row1.Cells(“LastName”).Value = “Griffin”
    row1.Cells(“FamilyID”).Value = 1
    row1.Cells(“Occupation”).Value = “Fisherman”
    row1.EndEdit()

    Dim row2 As Xceed.Grid.DataRow = grid.DataRows.AddNew()
    row2.Cells(“FirstName”).Value = “Homer”
    row2.Cells(“LastName”).Value = “Simpson”
    row2.Cells(“FamilyID”).Value = 2
    row2.Cells(“Occupation”).Value = “Nuclear Technician”
    row2.EndEdit()

    grid.FixedHeaderRows.Add(New ColumnManagerRow())

    Dim detail As New DetailGrid()

    detail.HeaderRows.Add(New ColumnManagerRow())
    detail.Columns.Add(New Column(“FirstName”, GetType(String)))
    detail.Columns.Add(New Column(“Relationship”, GetType(String)))
    detail.Columns.Add(New Column(“FamilyID”, GetType(Integer)))
    grid.DetailGridTemplates.Add(detail)

    AddHandler grid.InitializingDetailGrid, AddressOf Me.init_details

    ‘ Because we called BeginInit at the beginning of the process
    ‘ we must call EndInit otherwise none of our modifications
    ‘ will be applied to the grid.
    grid.EndInit()
    End Main()

    Private Sub init_details(ByVal sender As Object, ByVal e As InitializingDetailGridEventArgs)

    Select Case CType(e.Grid.ParentDataRow.Cells(“FamilyID”).Value, Integer)
    Case 1
    Dim row1 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row1.Cells(“FirstName”).Value = “Lois”
    row1.Cells(“Relationship”).Value = “Wife”
    row1.Cells(“FamilyID”).Value = 1
    row1.EndEdit()
    Dim row2 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row2.Cells(“FirstName”).Value = “Meg”
    row2.Cells(“Relationship”).Value = “Daughter”
    row2.Cells(“FamilyID”).Value = 1
    row2.EndEdit()
    Dim row3 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row3.Cells(“FirstName”).Value = “Chris”
    row3.Cells(“Relationship”).Value = “Son”
    row3.Cells(“FamilyID”).Value = 1
    row3.EndEdit()
    Dim row4 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row4.Cells(“FirstName”).Value = “Stewie”
    row4.Cells(“Relationship”).Value = “Son”
    row4.Cells(“FamilyID”).Value = 1
    row4.EndEdit()
    Dim row5 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row5.Cells(“FirstName”).Value = “Brian”
    row5.Cells(“Relationship”).Value = “Dog”
    row5.Cells(“FamilyID”).Value = 1
    row5.EndEdit()

    Case 2

    Dim row1 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()

    row1.Cells(“FirstName”).Value = “Marge”
    row1.Cells(“Relationship”).Value = “Wife”
    row1.Cells(“FamilyID”).Value = 2
    row1.EndEdit()

    Dim row2 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row2.Cells(“FirstName”).Value = “Bart”
    row2.Cells(“Relationship”).Value = “Son”
    row2.Cells(“FamilyID”).Value = 2
    row2.EndEdit()

    Dim row3 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row3.Cells(“FirstName”).Value = “Lisa”
    row3.Cells(“Relationship”).Value = “Daughter”
    row3.Cells(“FamilyID”).Value = 2
    row3.EndEdit()
    Dim row4 As Xceed.Grid.DataRow = e.Grid.DataRows.AddNew()
    row4.Cells(“FirstName”).Value = “Maggie”
    row4.Cells(“Relationship”).Value = “Daughter”
    row4.Cells(“FamilyID”).Value = 2
    row4.EndEdit()
    End Select

    End Sub

    Imported from legacy forums. Posted by Jacobo (had 2350 views)

    User (Old forums)
    Member
    Post count: 23064

    The only other possibility is to add each row in the detail grid row by row for each parent row. But at the end, it is equivalent.

    i.e. :

    Dim mainRow As Xceed.Grid.DataRow = grid.DataRows.AddNew()
    mainRow.Cells(“FirstName”).Value = “Peter”
    mainRow.Cells(“LastName”).Value = “Griffin”
    mainRow.Cells(“FamilyID”).Value = 1
    mainRow.Cells(“Occupation”).Value = “Fisherman”
    mainRow.EndEdit()

    mainRow = grid.DataRows.AddNew()
    mainRow.Cells(“FirstName”).Value = “Homer”
    mainRow.Cells(“LastName”).Value = “Simpson”
    mainRow.Cells(“FamilyID”).Value = 2
    mainRow.Cells(“Occupation”).Value = “Nuclear Technician”
    mainRow.EndEdit()

    Dim subRow = grid.DataRows[ 0 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Lois”
    subRow.Cells(“Relationship”).Value = “Wife”
    subRow.Cells(“FamilyID”).Value = 1
    subRow.EndEdit()

    subRow = grid.DataRows[ 0 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Meg”
    subRow.Cells(“Relationship”).Value = “Daughter”
    subRow.Cells(“FamilyID”).Value = 1
    subRow.EndEdit()

    subRow = grid.DataRows[ 0 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Chris”
    subRow.Cells(“Relationship”).Value = “Son”
    subRow.Cells(“FamilyID”).Value = 1
    subRow.EndEdit()

    subRow = grid.DataRows[ 0 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Stewie”
    subRow.Cells(“Relationship”).Value = “Son”
    subRow.Cells(“FamilyID”).Value = 1
    subRow.EndEdit()

    subRow = grid.DataRows[ 0 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Brian”
    subRow.Cells(“Relationship”).Value = “Dog”
    subRow.Cells(“FamilyID”).Value = 1
    subRow.EndEdit()

    subRow = grid.DataRows[ 1 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Marge”
    subRow.Cells(“Relationship”).Value = “Wife”
    subRow.Cells(“FamilyID”).Value = 2
    subRow.EndEdit()

    subRow = grid.DataRows[ 1 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Bart”
    subRow.Cells(“Relationship”).Value = “Son”
    subRow.Cells(“FamilyID”).Value = 2
    subRow.EndEdit()

    subRow = grid.DataRows[ 1 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Lisa”
    subRow.Cells(“Relationship”).Value = “Daughter”
    subRow.Cells(“FamilyID”).Value = 2
    subRow.EndEdit()

    subRow = grid.DataRows[ 1 ].DetailGrids[ 0 ].DataRows.AddNew();

    subRow.Cells(“FirstName”).Value = “Maggie”
    subRow.Cells(“Relationship”).Value = “Daughter”
    subRow.Cells(“FamilyID”).Value = 2
    subRow.EndEdit()

    Imported from legacy forums. Posted by André (had 3116 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.