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


    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

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

    <SPAN class=kwd></SPAN> 

  • 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:

    <span class="kwd">Public Class</span> Form1

    <span class="kwd">Private</span> dv <span class="kwd">As</span> System.Data.DataView

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

    dv = table.DefaultView
    dv.Sort = <span class="st">"B"</span>
    FpSpread1.DataSource = dv

    <span class="kwd">End Sub

    Private Sub</span> Button1_Click(<span class="kwd">ByVal</span> sender <span class="kwd">As</span> System.<span class="kwd">Object</span>, <span class="kwd">ByVal</span> e <span class="kwd">As</span> System.EventArgs) <span class="kwd">Handles</span> Button1.Click
    dv.Sort = <span class="st">"A"</span>
    <span class="kwd">End Sub
    End Class</span>
  • 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


    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