Why do I have to set DataSource = Nothing when resetting it

Posted by: j2associates on 8 September 2017, 12:47 pm EST

  • Posted 8 September 2017, 12:47 pm EST

    Hello all,


    In the attached sample project, I attempt to reset the FpSpread by using the following line:


    Me.FpSpread1.DataSource = m_DataSet.Tables("TestData")


    However, the FpSpread does not display properly unless I set the DataSource to nothing first. Is this a bug? To see the difference, Click the Add Rows button a couple of times and then Click Reset with and without the Clear DataSource check box checked.


    2007/09/AddUnboundRow AddRowToDataSet.zip
  • Replied 8 September 2017, 12:47 pm EST

    Hello,


    1) When the DataSource of the Spread is changed, Spread automatically replaces the DataModel with a new DataModel that just has the bound rows.


    2) I am not sure what you are seeing here with. Are you asking why the unbound rows are sorting?

  • Replied 8 September 2017, 12:47 pm EST

    The behavior described above changes depending upon the DataSource as summarized below:


    DataSource


    DataTable - Non clearing behavior is seen


    DataView - If DataView.Sort property is NOT referenced Non clearing behavior is NOT seen
    DataView - If Sort property is referenced via FarPoint GetDataView method Non clearing behavior is NOT seen
    DataView - If DataView.Sort property is referenced the Non clearing behavior is seen


    So the problem shows up when the DataSource is a DataTable or if the Windows DataView Sort property is referenced. I have attached an updated sample project which shows the behavior.


    2007/09/AddUnboundRow AddRowToDataSet2.zip
  • Replied 8 September 2017, 12:47 pm EST

    Hello,


    I think this may be a bit confusing. I will try to explain what you are seeing. In the first post, you are binding the Spread DataSource to the same object it was already bound to. Thus, a change is not made and nothing us updated. The next post, the same thing is happening in theory. The times you see a change made as you expect, you are binding the Spread to a different DataSource.


    If you were to click the DataView option, it would not matter what option you chose for sort, the unbound rows would go away as you expect, since Spread is changing it's DataSource from DataTable to DataView. Then, if you checked the DataTable option, it would work because the Spread is binding to a different object.

  • Replied 8 September 2017, 12:47 pm EST

    Hello Scott,


    Thanks for the response. I see what you are saying regarding nothing changing when I reset the DataSource to the original DataTable. The problem children are the Unbound data rows that are added using the FarPoint AddUnboundRows method. Why are these cleared when I set the DataSource to Nothing if they are Unbound rows? Shouldn't they remain in that case?


    Thanks for helping to clarify what is going on here!

  • Replied 8 September 2017, 12:47 pm EST

    A further question regarding Unbound rows. Why are they sorted since the sort is applied to the underlying bound DataSource? Shouldn't they just sit there until they are added to the DataSource? Is this getting into Spread Sort vs Model Sort and that kind of thing? Thanks again for the help!
  • Replied 8 September 2017, 12:47 pm EST

    re: 2, yes I am asking why the unbound rows are sorting. Thanks!
  • Replied 8 September 2017, 12:47 pm EST

    Hello,


    How are you sorting the DataSource? If you are sorting the DataModel in the Spread, then these rows will sort. If you are sorting the DataView, then onlyy the rows in the DataView should be sorted.

  • Replied 8 September 2017, 12:47 pm EST

    I normally do something like this:


    Me.FpSpread1.ActiveSheet.GetDataView(False).Sort = "SortCol1 DESC, SortCol2, SortCol3".


    How do I sort using the Model?

  • Replied 8 September 2017, 12:47 pm EST

    Hello,


    You can use the SortRange method and pass in the rows 1 to Count - 1 on the bound DataSource.

Need extra support?

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

Learn More

Forum Channels