Spread is displaying in wrong row order

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

  • Posted 8 September 2017, 12:45 pm EST

    Hello all,


    I have a spread bound to a DataView containing 3 columns, SortHeight, SortHeight2 and SortRow. The DataView is popuplated by parsing a text file. To get the initial order correct, it is sorted by SortHeight DESC, SortHeight2 DESc and SortRow. This is all working properly.


    Once the DataView is loaded, the sort property is changed to SortRow. However, the spread still displays in the original order until the user clicks in the spread somewhere, at which time it then reorders itself correctly. For example, it will display with SortRow = 1, 2, 0 in the spread.


    How can I force the spread to show correctly from the beginning? I have tried Refresh, setting the DataSource to Nothing and then resetting the DataSource to the DataView and nothing helps. Thanks in advance for any ideas and/or suggestions!


     

  • Replied 8 September 2017, 12:45 pm EST

    Hello,


    Since clicking the Spread causes the spread to peform a layout, you can try calling the PerformLayout method after change the DataSource on the Spread. If this does not work, could you post a small zipped project reproducing this issue for us to debug? Are you sorting the DataView or the Spread?

  • Replied 8 September 2017, 12:45 pm EST

    Hello Scott,


    Thanks for the suggestion. I tried calling PerformLayout and that did not help either. Unfortunately, this is a very large project so I can't zip it up and attach it as much as I would like to do so.


    I did find a work-around which at least allows me to make sure that everything is in sync. I react to the ListChanged event of the underlying DataView which is the DataSource for the spread and which is defined as a form level WithEvents variable. For the benefit of others, here is some sample code.


    Private WithEvents MyDataView As DataView


    Private Sub MyDataView_ListChanged( _
        ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs)
            Handles MyDataView.ListChanged
        If e.ListChangedType = System.ComponentModel.ListChangedType.ItemMoved Then
            ' Do my synchronization code here.
        End If
    End Sub


     

  • Replied 8 September 2017, 12:45 pm EST

    The data model should handle that.  Are you assigning your DataView as the data source?  When I try that in a quick sample, it appears to work fine:

     
    Public Class Form1

    Private dv As System.Data.DataView

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim table As New System.Data.DataTable
    table.Columns.AddRange(New System.Data.DataColumn() {New System.Data.DataColumn("A"), New System.Data.DataColumn("B"), New System.Data.DataColumn("C")})
    table.Rows.Add(New Object() {"z", "a", "g"})
    table.Rows.Add(New Object() {"y", "b", "a"})
    table.Rows.Add(New Object() {"x", "c", "x"})

    dv = table.DefaultView
    dv.Sort = "B"
    FpSpread1.DataSource = dv

    End Sub

    Private Sub
    Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    dv.Sort = "A"
    End Sub
    End Class

     
  • Replied 8 September 2017, 12:45 pm EST

    Thanks for taking time to investigate this a little bit! I cannot reproduce it on smaller projects either.


    In your earlier response, you said something to the effect of the data model should handle that. I'm not sure what you are referring to at that point, your code, my code or something else. Could you please elaborate a bit on what you meant by that statement? Thanks!

  • Replied 8 September 2017, 12:45 pm EST

    Hello,


    The DataModel is the model object in Spread that contains all data, notes, formulas, etc. for the SheetView. What he meant was our DataModel object should listen to changes made on the bound DataSource and automatically update.

Need extra support?

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

Learn More

Forum Channels