Home Forums WPF controls Xceed DataGrid for WPF How to make two way binding work with xml data binding

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22875 |

    Hello,

    I have an editable xceed grid that is databound to xml. When I edit the cells, the changed value is not written to the bound xml island. I have tried setting the binding mode to two way but did not get any success. Please let me know if you have any suggestions.

    Thanks in advance.

    Imported from legacy forums. Posted by Ranjana (had 2635 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    Are you using XmlDataProvider class as the ItemsSource of the DataGridControl?

    I ask because after much experimentations, we did not find a way to “propagate” the changes back to the XML source using the XmlDataProvider… (at the same time, it seems the “refreshing” of the XmlDataProvider also forces some reverts of “in-memory editions”, such as when you are grouping or sorting the items).

    It is already part of our plans to develop a “data provider” for XML that will allow updates and even insertion, but we have no timeframes yet for this feature.

    In the mean-time… If this is something really important for you… I can suggest an investigation path: I suggest Loading the XmlDocument in code-behind, creating a collection of XmlNode in code-behind, bind the collection to the ItemsSource and update the Document when edition completes… This has much more chances of working appropriately (while I did not try this solution myself, I think it have good chances of success).

    Imported from legacy forums. Posted by Marcus [Xceed] (had 345 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Marcus for the quick reply.
    I am using an XmlDataProvider class as the itemsource for the datagrid. Actually it is imperative for us to get this to work since a lot of our code depends on the dataisland being current with the edited data it is bound to. We do have to build the xml dynamically but the xaml has the bound definitions already so we do update the datasource when we deliver the data to the UI. On edition though we were not updating the datasource manually. I tried to do a manual refresh of the document but that did not work(first code section). I tried to do this manually(second code section) and was able to do so.

    The problem I am having now is what event should I catch for edition to be complete and when is the edition actually complete? Do I have to call the endedit always to force the edition to be completed – the lost focus on a cell did not seem to update the actual content.

    So this code did not update the data island:
    private void Cell_LostFocus(object sender, RoutedEventArgs e)
    {

    DataCell xceedCell = sender as DataCell;
    if (xceedCell != null){
    string name = xceedCell.FieldName;
    xceedCell.EndEdit();
    Page page = contentFrame.Content as Page;
    XmlDataProvider xmlDataProv = page.FindResource(“DataProvider”) as XmlDataProvider;
    xmlDataProv.Refresh();
    }

    }

    This seems to work:
    private void Grid_LostFocus(object sender, RoutedEventArgs e)
    {
    DataGridControl xceedGrid = sender as DataGridControl;
    if (null != xceedGrid)
    {
    if (xceedGrid.SelectedIndex > -1)
    {
    XmlElement xel = xceedGrid.SelectedItem as XmlElement;
    DataRow row =
    xceedGrid.ItemContainerGenerator.ContainerFromItem
    (xceedGrid.CurrentItem) as DataRow;
    if (row != null)
    row.EndEdit();
    //the xmlnodename is the node on the dataisland – I need to derive that – //a little cumbersome
    XmlNode xnode = xel.SelectSingleNode(xmlnodename);
    xnode.InnerXml = row.Cells[0].Content.ToString();//the cell has to be
    //derived too
    }
    }
    }

    The problem I am seeing is the lost focus fires a little sporadically in our model where we load a page dynamically.

    Please let me know if you have any suggestions.
    Thanks.

    Imported from legacy forums. Posted by Ranjana (had 3558 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

     Above u had said “It is already part of our plans to develop a “data provider” for XML that will allow updates and even insertion, but we have no timeframes yet for this feature.”

    Have you guys implemented this data provider for xml yet.I am facing the same issue of 2 way binding datagrid with an i/p xml file?

    Thanks,

    Abhijit 

     

    Imported from legacy forums. Posted by Abhijit (had 726 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.