Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Nested grid...

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 grid...
Link Posted: 16-Dec-2006 23:43
I need some help with using nested grids, I am having a hard time trying to figure them out.  Below is the code that I am currently using:


        Dim myDB As New DBAccess

        If myDB.Connect(\"MRCS\") = False Then
            Exit Sub
        Else
            Dim myDA As New OleDb.OleDbDataAdapter(\"spQryParentComments\", myDB.myConn)
            myDA.TableMappings.Add(\"Table\", \"Original\")
            myDA.SelectCommand.CommandType = CommandType.StoredProcedure
            myDA.SelectCommand.Parameters.Add(New OleDb.OleDbParameter(\"@projName\", OleDb.OleDbType.VarChar)).Value = MRCSData.Instance.ProjectName
            Dim myDS As New DataSet(\"Original\")

            myDA.Fill(myDS)

            Dim myChildDA As New OleDb.OleDbDataAdapter(\"spQryChildComments\", myDB.myConn)
            myChildDA.TableMappings.Add(\"Table\", \"History\")
            myChildDA.SelectCommand.CommandType = CommandType.StoredProcedure
            myChildDA.SelectCommand.Parameters.Add(New OleDb.OleDbParameter(\"@projName\", OleDb.OleDbType.VarChar)).Value = MRCSData.Instance.ProjectName

            myChildDA.Fill(myDS)

            Dim parentColumn As DataColumn = myDS.Tables(\"Original\").Columns(\"commID\")
            Dim childColumn As DataColumn = myDS.Tables(\"History\").Columns(\"commID\")
            Dim relation As DataRelation = New System.Data.DataRelation(\"NumbersConnections\", parentColumn, childColumn)

            myDS.Relations.Add(relation)

            myDB.DisConnect()

            Me.lstReviewComm.Rows.Items.Clear()
            Me.lstReviewComm.Rows.DataSource = myDS
            Me.lstReviewComm.Rows.DataMember = \"Original\"
            Me.lstReviewComm.Focus()
        End If


However it does not display the data correctly, please see the attached image.



Any help whould be appreshaited.

Thanks in advance

Simon
Link Posted: 18-Dec-2006 08:40
Seems that you've incorrectly initialized columns.
Please check the field names of added columns, Column.FieldName is used to fetch data from datasource.
Link Posted: 18-Dec-2006 18:37
I have fixed the column.fieldname so they reflect the column names from my table and it now displays the data fine.  However it is not nesting the data e.g. displaying the '+' button.

What am I doing wrong, below is the code I am using:


        Dim myDB As New DBAccess

        If myDB.Connect(\"MRCS\") = False Then
            Exit Sub
        Else
            Dim myDA As New OleDb.OleDbDataAdapter(\"spQryParentComments\", myDB.myConn)
            myDA.TableMappings.Add(\"Table\", \"Original\")
            myDA.SelectCommand.CommandType = CommandType.StoredProcedure
            myDA.SelectCommand.Parameters.Add(New OleDb.OleDbParameter(\"@projName\", OleDb.OleDbType.VarChar)).Value = MRCSData.Instance.ProjectName
            Dim myDS As New DataSet(\"Original\")
            myDA.Fill(myDS)

            Dim myChildDA As New OleDb.OleDbDataAdapter(\"spQryChildComments\", myDB.myConn)
            myChildDA.TableMappings.Add(\"Table\", \"History\")
            myChildDA.SelectCommand.CommandType = CommandType.StoredProcedure
            myChildDA.SelectCommand.Parameters.Add(New OleDb.OleDbParameter(\"@projName\", OleDb.OleDbType.VarChar)).Value = MRCSData.Instance.ProjectName
            myChildDA.Fill(myDS)

            Dim parentColumn As DataColumn = myDS.Tables(\"Original\").Columns(\"commID\")
            Dim childColumn As DataColumn = myDS.Tables(\"History\").Columns(\"commID\")
            Dim relation As DataRelation = New System.Data.DataRelation(\"NumbersConnections\", parentColumn, childColumn)

            myDS.Relations.Add(relation)

            myDB.DisConnect()

            Me.lstReviewComm.Rows.Items.Clear()
            Me.lstReviewComm.Rows.DataSource = myDS
            Me.lstReviewComm.Rows.DataMember = \"Original\"
            Me.lstReviewComm.Focus()
        End If


Thanks in advance

Simon
Link Posted: 19-Dec-2006 03:45
I have kind of fixed the above problem, how ever I have a couple of other problems.

1)  I am using the above code but this adds a extra row on at the end of the flygrid, I know I can change the ShowAddNewRow property to false to remove this.  However when I change this to false an error is then caused on this line of code:     Dim selection As NodeBase() = Me.lstReviewComm.Rows.GetSelection

See full code below:


    Private Sub lstReviewComm_NodeSelectedChange(ByVal sender As Object, ByVal node As NineRays.Windows.Forms.Data.NodeBase) Handles lstReviewComm.NodeSelectedChange
    Dim selection As NodeBase() = Me.lstReviewComm.Rows.GetSelection

        If Not selection Is Nothing Then
            If (selection.Length = 0) Then
                Exit Sub
            Else
                Try
                    loadReviewCommInfo(Me.lstReviewComm.Selected.Item(0).ToString)
                    Me.picThumbNail.Cursor = Cursors.Hand
                Catch
                    Exit Sub
                End Try
            End If
        Else
            Exit Sub
        End If

    End Sub


2) I am unable to get the nested column to be added in one column with the number and show the tree dotted lines.  See image below




Thanks in advance

Simon[/img]
Link Posted: 19-Dec-2006 11:04
Please see the dataBoundGridForm.vb file of the FlyGrid.Net VB Demo (you can find this file in the \\Demo\\VB folder of FlyGrid.Net installation folder), PrepareColumns procedure to more clearly understand how to organize nested data (master-detail view) in databound mode.
[list=1]
In short words follow the scenario described below:
  • Add columns to the root level and setup them:
    example:
    flyGrid.Columns.Items.Add(new Column(\"ColumnCaption\", \"BoundFieldName\"))
  • [/*:m]
  • Get the nested columns:
    example:
    Function GetNestedColumns(ByVal cols as Columns) as Columns
      Return cols.NestedColumns
    End Function

    usage:

    Dim subColumns = GetNestedColumns(flyGrid.Columns)
    Dim subsubColumns = GetNestedColumns(subColumns)
  • [/*:m]
  • Do the step 1 for the nested columns.
  • [/*:m]
  • Specify DataMember for the root data:
    flyGrid.Rows.DataMember = \"Master\"
  • [/*:m]
  • If a root data has a several relations - specify the NestedDataMember for the nested data (details):
    flyGrid.Columns.NestedDataMember = \"Details\"

    If a root data has a single relation this is not necessary.
  • [/*:m]
  • Connect to the DataSource
    flyGrid.Rows.DataSource = myDataSet
  • [/*:m][/list:o]

    Additionaly you can see the differentDetailsFrm.vb code to see how to organize multi-relation nested grids.
    Link Posted: 19-Dec-2006 15:08
    Thanks for the help, I will try that, however could you also answer question 1 on my previous post.

    Thanks in advance

    Simon
    Link Posted: 28-Dec-2006 01:27
    bump...
    Link Posted: 03-Jan-2007 21:21
    bump
    Link Posted: 08-Jan-2007 09:42
    I have managed to get this to work by using the below code, however if I try to add more than one item onto the nested grid it does not show the second one correctly and causes an error:


    Private Sub loadReviewComm()
            Dim myDB As New DBAccess

            If myDB.Connect(\"MRCS\") = False Then
                Exit Sub
            Else
                Dim myDA As New OleDb.OleDbDataAdapter(\"spQryParentComments\", myDB.myConn)
                myDA.TableMappings.Add(\"Table\", \"Original\")
                myDA.SelectCommand.CommandType = CommandType.StoredProcedure
                myDA.SelectCommand.Parameters.Add(New OleDb.OleDbParameter(\"@projName\", OleDb.OleDbType.VarChar)).Value = MRCSData.Instance.ProjectName
                Dim myDS As New DataSet(\"Original\")
                myDA.Fill(myDS)

                Dim myChildDA As New OleDb.OleDbDataAdapter(\"spQryChildComments\", myDB.myConn)
                myChildDA.TableMappings.Add(\"Table\", \"History\")
                myChildDA.SelectCommand.CommandType = CommandType.StoredProcedure
                myChildDA.SelectCommand.Parameters.Add(New OleDb.OleDbParameter(\"@projName\", OleDb.OleDbType.VarChar)).Value = MRCSData.Instance.ProjectName
                myChildDA.Fill(myDS)

                Dim parentColumn As DataColumn = myDS.Tables(\"Original\").Columns(\"commID\")
                Dim childColumn As DataColumn = myDS.Tables(\"History\").Columns(\"commID\")
                Dim relation As DataRelation = New System.Data.DataRelation(\"NumbersConnections\", parentColumn, childColumn)

                myDS.Relations.Add(relation)

                myDB.DisConnect()

                Me.lstReviewComm.Rows.Items.Clear()
                Me.lstReviewComm.Rows.DataSource = myDS
                Me.lstReviewComm.Rows.DataMember = \"Original\"
                Me.lstReviewComm.Focus()
            End If
        End Sub




    Thanks in advance

    Simon
    Link Posted: 15-Jan-2007 02:15
    Can anyone help me with this problem, as it is holding me release my software.

    Thanks in advance

    Simon