Two Way Data Binding in Spread WPF?

Posted by: nathanhanson on 10 September 2017, 1:59 am EST

  • Posted 10 September 2017, 1:59 am EST

    Please forgive if this has been discussed previously, I did a forum search and didn't see much. I'm new to Spread but experienced in WPF. I'm looking to bind the control so a sheet represents an IEnumerable collection of objects with various DependencyProperties that will make up the various columns in the sheet. I'd like to have these bindings be two way, such that when a user changes a value in a cell, it's updated in the appropriate property in the corresponding object. However, the Spread WPF documentation states:

    "GcSpreadSheet supports one way data binding. Changes to the source automatically update the target but, changes to the target are not propagated back to the source."

    So does this mean, I've got to use code behind to handle events when a cell changes and update the value in the object myself? Is that what you all are doing? Handling things in this way seems much more involved and more difficult to maintain than two way data bindings. I'd love to hear people's thoughts. Thanks!
  • Marked as Answer

    Replied 10 September 2017, 1:59 am EST

    Hi,

    That is correct. Unlike the WinForms or ASP.NET controls, Spread for WPF does not support two-way data-binding. Per the documentation here:

    http://sphelp.grapecity.com/WebHelp/SpreadWPF/webframe.html#DataBindingF.html

    It shouldn't actually be too difficult to update, since if you set the Sheet's data source, then the row indices and column headers would actually correspond to those in the Data Source (in the example above, a DataTable). So just accessing the data in cells in Spread via the Worksheet.GetValue() method:

    http://sphelp.grapecity.com/WebHelp/SpreadWPF/webframe.html#GrapeCity.WPF.SpreadSheet.Data~GrapeCity.Windows.SpreadSheet.Data.Worksheet~GetValue(Int32,Int32).html

    Let me know if that helps.

    Thanks,
    Reeva
  • Replied 10 September 2017, 1:59 am EST

    Thank you Reeva! I really appreciate the response. That approach should work for my needs. I'll give it a shot.
  • Replied 28 March 2022, 9:03 am EST

    I'm back to this very same question almost five years later. 😁 What I need to figure out is the mapping from the column and row in the SheetView cell the user changed back to the column and row for that cell in the underlying table. Note that I allow users to sort, filter and re-order columns in the SheetView. So the mapping isn't straight forward. In Spread WinForms, I had useful functions like GetModelRowFromViewRow() to help me. Are there similar functions to help with the mapping in WPF?
  • Replied 20 June 2022, 6:00 pm EST

    Hi Nathan,

    After sorting or filtering bounded DataSource, it will reflect back to the SpraedSheet i.e., updating cell position in DataTable will update the specific position of cells in SpreadSheet same as DataTable. You only need to invoke GetValue() method to get the corresponding cell value.

    Regards,
    Nitin.
Need extra support?

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

Learn More

Forum Channels