templates

Posted by: kpk on 8 September 2017, 1:56 pm EST

  • Posted 8 September 2017, 1:56 pm EST

    I have a grid that is bound to a datatable.  Users are allowed to move columns and I would like to persist where columns have moved to from session to session.  is there a way I can serialize the layout but still maintain the binding?
  • Replied 8 September 2017, 1:56 pm EST

    Hello,


    You should be able to Serialize and Deserialize the layout using a Binary Serialization.Here is the code that Serialize the layout on ColumnMove and Deserialize the layout on a Button click event adding a new sheet to Spread.I hope it will help you.

    <FONT color=#0000ff size=2><FONT color=#0000ff size=2>

    Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> FpSpread1_ColumnDragMoveCompleted(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Object</FONT></FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> FarPoint.Win.Spread.DragMoveCompletedEventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> FpSpread1.ColumnDragMoveCompleted


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> stream </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.IO.Stream = System.IO.File.Open(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"save.bin"</FONT></FONT><FONT size=2>, System.IO.FileMode.CreateNew)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> binf </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()


    binf.Serialize(stream, FpSpread1.Sheets(0))


    stream.Close()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub

    </FONT></FONT><FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> Button1_Click(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> Button1.Click


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> binf </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> stream </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.IO.Stream = System.IO.File.Open(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"save.bin"</FONT></FONT><FONT size=2>, System.IO.FileMode.Open)


    FpSpread1.Sheets.Add(binf.Deserialize(stream))


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT>


    <FONT color=#0000ff size=2><FONT color=#0000ff size=2></FONT></FONT> 


    <FONT color=#0000ff size=2><FONT color=#0000ff size=2></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2><FONT color=#000000>Regards,</FONT>

    </FONT></FONT>
Need extra support?

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

Learn More

Forum Channels