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:


    <font face="courier new,courier">fpSpread1.sheets(0).DataSource = dsCustomersAndOrder</font> 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:

    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:blue;">Dim</span>
    dsCustomersAndOrders <span style="color:blue;">As</span> DataSet = <span style="color:blue;">New</span> DataSet(<span>"CustomersAndOrders"</span>)<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><o:p> </o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:blue;">Dim</span>
    dtCustomer <span style="color:blue;">As</span> DataTable =
    dsCustomersAndOrders.Tables.Add(<span>"Customers"</span>)<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:blue;">Dim</span>
    pkCustomerID <span style="color:blue;">As</span> DataColumn =
    dtCustomer.Columns.Add(<span>"CustomerID"</span>,
    Type.GetType(<span>"System.Int32"</span>))<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>dtCustomer.Columns.Add(<span>"CustomerName"</span>, Type.GetType(<span>"System.String"</span>))<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>dtCustomer.PrimaryKey = <span style="color:blue;">New</span> DataColumn() {pkCustomerID}<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><o:p> </o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:blue;">Dim</span>
    dtOrders <span style="color:blue;">As</span> DataTable =
    dsCustomersAndOrders.Tables.Add(<span>"Orders"</span>)<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:blue;">Dim</span>
    pkOrderID <span style="color:blue;">As</span> DataColumn = dtOrders.Columns.Add(<span>"OrderID"</span>, Type.GetType(<span>"System.Int32"</span>))<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>dtOrders.Columns.Add(<span>"OrderQuantity"</span>, Type.GetType(<span>"System.Int32"</span>))<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>dtOrders.Columns.Add(<span>"CompanyName"</span>, Type.GetType(<span>"System.String"</span>))<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>dtOrders.Columns.Add(<span>"CustomerID"</span>, Type.GetType(<span>"System.Int32"</span>))<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>dtOrders.PrimaryKey = <span style="color:blue;">New</span> DataColumn() {pkOrderID}<o:p></o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><o:p> </o:p></span>



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:green;">'If you
    comment out this line, no error occurs (because there is no relationship); but if you leave the line it, the .DataSource</span></span>


    <span style="font-size:10pt;font-family:'Courier New';"><span style="color:green;"></span><span>        </span><span style="color:green;">'assignment below will throw an error.</span></span>


    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>dsCustomersAndOrders.Relations.Add(<span>"CustomerOrders"</span>, dtCustomer.Columns(<span>"CustomerID"</span>), dtOrders.Columns(<span>"CustomerID"</span>))<o:p></o:p></span>


     



    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:green;">'Note that the newly created dataset has zero rows</span><span></span></span>


    <span style="font-size:10pt;font-family:'Courier New';"><span>        </span>FpSpread1.Sheets(0).DataSource =
    dsCustomersAndOrders<o:p></o:p></span>



     


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


    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