Binding to empty hierarchical dataset throws error in 4.0 - Is there a workaround?

Posted by: c17 on 8 September 2017, 1:31 pm EST

  • Posted 8 September 2017, 1:31 pm EST


    Hi,


    As discussed in this thread (http://www.clubfarpoint.com/Forums/forums/thread/68507.aspx), with version 4.0.2005.2005, if you bind the spread to a dataset with zero rows, you get this error under certain conditions:


    fpSpread1.sheets(0).DataSource = dsCustomersAndOrder throws this error:


    System.ArgumentOutOfRangeException was unhandled
      Message="Invalid row index specified (must be between 0 and -1).
    Parameter name: row
    Actual value was 0."
      ParamName="row"
      Source="FarPoint.Win.Spread"
      StackTrace:
           at FarPoint.Win.Spread.SheetView.IsRowExpanded(Int32 row)
           at FarPoint.Win.Spread.SpreadView.a(Int32 A_0, Boolean A_1)
           at FarPoint.Win.Spread.SpreadView.h(Boolean A_0)
           at FarPoint.Win.Spread.SpreadView.f3()
           at FarPoint.Win.Spread.SpreadView.b(Object A_0, SheetAxisModelEventArgs A_1)
           at FarPoint.Win.Spread.Model.SheetAxisModelEventHandler.Invoke(Object sender, SheetAxisModelEventArgs e)
           at FarPoint.Win.Spread.Model.BaseSheetAxisModel.OnChanged(SheetAxisModelEventArgs e)
           at FarPoint.Win.Spread.Model.BaseSheetAxisModel.FireChanged(Int32 index, Int32 count, SheetAxisModelEventType type)
           at FarPoint.Win.Spread.Model.DefaultSheetAxisModel.FarPoint.Win.Spread.Model.IMovable.Remove(Int32 index, Int32 count)
           at FarPoint.Win.Spread.SheetView.OnRemoveRows(Int32 row, Int32 count)
           at FarPoint.Win.Spread.SheetView.OnDataModelChanged(Object sender, SheetDataModelEventArgs e)
           at FarPoint.Win.Spread.Model.SheetDataModelEventHandler.Invoke(Object sender, SheetDataModelEventArgs e)
           at FarPoint.Win.Spread.Model.BaseSheetDataModel.OnChanged(SheetDataModelEventArgs e)
           at FarPoint.Win.Spread.Model.BaseSheetDataModel.FireChanged(Int32 row, Int32 column, Int32 rowCount, Int32 columnCount, SheetDataModelEventType type)
           at FarPoint.Win.Spread.Model.DefaultSheetDataModel.set_DataSource(Object value) 


    I don't think it was realized/discussed in that thread, but the problem occurs ONLY if the dataset in question has relationships.  You can prove it by placing this code in Form Load on a form that has nothing but a spread on it:

            Dim
    dsCustomersAndOrders As DataSet = New DataSet("CustomersAndOrders")



     



            Dim
    dtCustomer As DataTable =
    dsCustomersAndOrders.Tables.Add("Customers")



            Dim
    pkCustomerID As DataColumn =
    dtCustomer.Columns.Add("CustomerID",
    Type.GetType("System.Int32"))



            dtCustomer.Columns.Add("CustomerName", Type.GetType("System.String"))



            dtCustomer.PrimaryKey = New DataColumn() {pkCustomerID}



     



            Dim
    dtOrders As DataTable =
    dsCustomersAndOrders.Tables.Add("Orders")



            Dim
    pkOrderID As DataColumn = dtOrders.Columns.Add("OrderID", Type.GetType("System.Int32"))



            dtOrders.Columns.Add("OrderQuantity", Type.GetType("System.Int32"))



            dtOrders.Columns.Add("CompanyName", Type.GetType("System.String"))



            dtOrders.Columns.Add("CustomerID", Type.GetType("System.Int32"))



            dtOrders.PrimaryKey = New DataColumn() {pkOrderID}



     



            'If you
    comment out this line, no error occurs (because there is no relationship); but if you leave the line it, the .DataSource


            'assignment below will throw an error.


            dsCustomersAndOrders.Relations.Add("CustomerOrders", dtCustomer.Columns("CustomerID"), dtOrders.Columns("CustomerID"))


     



            'Note that the newly created dataset has zero rows


            FpSpread1.Sheets(0).DataSource =
    dsCustomersAndOrders



     


    =======================================================================\


    So much for the bug, which will presumably get fixed in an upcoming maintenance release.  Now, my question is, can you suggest a workaround?  Since upgrading to 4.0, this has brought the work on my project to a halt, since many, many forms have hierarchical datasets, and of course it's perfectly legitimate for them to have zero rows.


    Thank you,


     C17


     


     


     


     

  • Replied 8 September 2017, 1:31 pm EST

    I have replied offline to this concern.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels