Welcome to the Xceed Community | Help
Community Search  
More Search Options

How can I get the Item from its DataRow?

Sort Posts: Previous Next
  •  03-23-2012, 1:43 PM Post no. 31885

    How can I get the Item from its DataRow?

    Usually I can just go

    MyObject underlyingItem = myDataGrid.GetItemFromContainer((DataRow) sender);

    But when sender is an insertionRow, GetItemFromContainer doesn't return the insertion row's underlying item, it returns a DataTemplate object. What gives?

  •  03-24-2012, 6:53 PM Post no. 31898 in reply to 31885

    Re: How can I get the Item from its DataRow?

    I found a solution - but so your developers know, I think there is a bug with GetItemFromContainer() when insertion rows are involved.

    The solution is to instead use ((Row) sender).DataContext

    • When the Row is a normal DataRow, this will give the MyObject underlyingItem correctly.
    • When the Row is an InsertionRow, and the InsertionRow is not currently being edited, this will give a DataTemplate object.
    • When the Row is an InsertionRow, and the InsertionRow IS currently being edited, this will correctly give the MyObject underlyingItem that has been created but not yet comitted.

    Note that whether an InsertionRow is currently being edited or not (i.e. whether or not the InsertionRow currently has an underlying item), GetItemFromContainer() will always return the DataTemplate of the InsertionRow, and I think that's a mistake.

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.