Spread Windows Forms 11.0 Product Documentation
Creating a Hierarchical Display Manually
Spread Windows Forms 11.0 Product Documentation > Developer's Guide > Managing Data Binding > Customizing Data Binding > Creating a Hierarchical Display Manually

You can manually (programmatically) create a hierarchical display as shown in the example below. The parent is the higher level of the hierarchy and the child is the lower level.

Example

This example creates two custom SheetView objects: one as the parent and one as the child. In the parent sheet, the example overrides the ChildRelationCount property and GetChildView and FindChildView methods. The ChildRelationCount is how many relations between this object and children objects (usually this is one).

The GetChildView is used to get the child sheet. It calls FindChildView to see if the sheet is already created. If it is, then use that sheet. If it is not, create a new child sheet.

The SheetName property of the child SheetView determines which parent row it is assigned to.

Override the ParentRowIndex property in the child SheetView to return the row number that child is assigned to. The SheetName in creating this sheet determines this number.

VB
Copy Code
...
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
     fpSpread1.Sheets.Clear()
     fpSpread1.Sheets.Add(New customSheet)
     fpSpread1.Sheets(0).RowCount = 10
     Dim i As Integer
     For i = 0 To 9
          If i <> 1 Then
               fpSpread1.Sheets(0).SetRowExpandable(i, False)
          End If
     Next i
End Sub
End Class

Public Class customSheet
Inherits FarPoint.Win.Spread.SheetView

  Public Overrides ReadOnly Property ChildRelationCount() As Integer
     Get
          Return 1
     End Get
  End Property

  Public Overrides Function GetChildView(ByVal row As Integer, ByVal relationIndex As Integer) As FarPoint.Win.Spread.SheetView
     Dim child As customChild = CType(FindChildView(row, 0), customChild)
     If Not (child Is Nothing) Then Return child
          child = New customChild
          child.RowCount = 5
          child.Parent = Me
          child.SheetName = row.ToString
          ChildViews.Add(child)
     Return child
  End Function

  Public Overrides Function FindChildView(ByVal row As Integer, ByVal relationIndex As Integer) As FarPoint.Win.Spread.SheetView
     Dim id As String = row.ToString
     Dim View As FarPoint.Win.Spread.SheetView
     For Each View In ChildViews
          If View.SheetName = id Then Return View
     Next
     Return Nothing
  End Function
End Class

Public Class customChild
Inherits FarPoint.Win.Spread.SheetView
   Public Overrides ReadOnly Property ParentRowIndex() As Integer        Get             Return CInt(SheetName)
      End Get
   End Property
End Class