Home - Forums-.NET - FlyGrid.Net (Windows Forms) - nested binding

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

nested binding
Link Posted: 25-Mar-2006 06:04
I'm trying to bind records from a SQL database to flygrid, much
like in the flygridDemo MasterDetail but everything binds except
nested columns related to the parent node.


Private Sub Load_VPN_Numbers()    
        Dim ds As DataSet
        ds = LoadTable("VIP_Select_VPN_Numbers", "VIP_Select_Connection")
        gridNumbers.Rows.Items.Clear()
        gridNumbers.Columns.NestedColumns = GetNestedColumns(gridNumbers)
        gridNumbers.Rows.DataSource = ds  
       gridNumbers.Rows.DataMember = "Numbers"
             gridNumbers.Focus()        
    End Sub  

Private Function GetNestedColumns(ByVal grid As FlyGrid) As Columns
        Dim nestedcols As Columns = New Columns(grid)
        nestedcols.Options = grid.Options
        Dim newnCol As Column = New Column("Ime", "First_Name")
        newnCol.Width = 100
        nestedcols.Items.Add(newnCol)
        newnCol = New Column("Prezime", "Last_Name")
        newnCol.Width = 120
        nestedcols.Items.Add(newnCol)
        newnCol = New Column("Aktivirano", "Activated")
        newnCol.Width = 75
        nestedcols.Items.Add(newnCol)
        newnCol = New Column("Suspendirano", "Suspended")
        newnCol.Width = 100
        nestedcols.Items.Add(newnCol)
        Return nestedcols
    End Function


Public Function LoadTable(ByVal s_procedure As String, ByVal s_procedure_child As String) As DataSet
dim options As Options = SerializableData.Load(OptionFileName, GetType(Options))
        Dim objConnection As New SqlConnection("server=" & options.SQL_Server & ";database=" & options.SQL_Database & ";user id=" & options.SQL_User & ";password=" & options.SQL_Password & ";Trusted_Connection=True")

        Dim parentAdapter As SqlDataAdapter = _
           New SqlDataAdapter()
        parentAdapter.TableMappings.Add("Table", "Numbers")

        objConnection.Open()
        Dim parentCommand As SqlCommand = New SqlCommand()
        With parentCommand
            .Connection = objConnection
            .CommandText = s_procedure
            .CommandType = CommandType.StoredProcedure
        End With

        parentAdapter.SelectCommand = parentCommand


        Dim dataSet As DataSet = New DataSet("Numbers")
        parentAdapter.Fill(dataSet)

        Dim childAdapter As SqlDataAdapter = _
            New SqlDataAdapter()
        childAdapter.TableMappings.Add("Table", "Connections")

        Dim childCommand As SqlCommand = New SqlCommand()
        With childCommand
            .Connection = objConnection
            .CommandText = s_procedure_child
            .CommandType = CommandType.StoredProcedure
        End With
        childAdapter.SelectCommand = childCommand


        childAdapter.Fill(dataSet)


        objConnection.Close()

        Dim parentColumn As DataColumn = dataSet.Tables("Numbers").Columns("VPNID")
        Dim childColumn As DataColumn = dataSet.Tables("Connections").Columns("VPNID")
        Dim relation As DataRelation = New _
           System.Data.DataRelation("NumbersConnections", _
           parentColumn, childColumn)

        dataSet.Relations.Add(relation)
        Return dataSet
    End Function


Any help appritiated. I just want simple databindings with nested columns
on items which have relation with another table.
Link Posted: 26-Mar-2006 22:17
You shouldn't create new columns instance, it is enough to refer to then nested columns:

Private Sub Load_VPN_Numbers()  
  Dim ds As DataSet
  ds = LoadTable("VIP_Select_VPN_Numbers", "VIP_Select_Connection")
  gridNumbers.Rows.Items.Clear()
  'refer to the nested columns of the root columns
  InitNestedColumns(GetNestedColumns(gridNumbers.Columns))
  gridNumbers.Rows.DataSource = ds  
  gridNumbers.Rows.DataMember = "Numbers"
  gridNumbers.Focus()      
End Sub

'return nested columns for the columns required
Private Function GetNestedColumns(ByVal cols as Columns) as Columns
   return cols.NestedColumns;
End Function

Private Sub InitNestedColumns(ByVal nestedcols As Columns)
  Dim newnCol As Column = New Column("Ime", "First_Name")
  newnCol.Width = 100
  nestedcols.Items.Add(newnCol)
  newnCol = New Column("Prezime", "Last_Name")
  newnCol.Width = 120
  nestedcols.Items.Add(newnCol)
  newnCol = New Column("Aktivirano", "Activated")
  newnCol.Width = 75
  nestedcols.Items.Add(newnCol)
  newnCol = New Column("Suspendirano", "Suspended")
  newnCol.Width = 100
  nestedcols.Items.Add(newnCol)  
End Function