Home Forums WPF controls Xceed DataGrid for WPF DataRow Source

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

    if you have the DataRow or DataCell how do you get the datasource item associated with that row?

    Imported from legacy forums. Posted by MiddleTommy (had 637 views)

    Xceed Support
    Member
    Post count: 5658

    The best way is to use the method:

    myDataGridControl.GetItemFromContainer( whateverDO )

    This method will work with the actual container (DataRow) but also with the DataCells and any other elements that are part of the DataRow and/or DataCell Template.

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

    User (Old forums)
    Member
    Post count: 23064

    how do you get the grid when you only have the
    datacell, or datarow

    Imported from legacy forums. Posted by MiddleTommy (had 362 views)

    User (Old forums)
    Member
    Post count: 23064

    For my bound grid using an ItemsSource of DataGridCollectionView, the DataRow.DataContext and Cell.DataContextis a reference to the corresponding object in my collection.

    Imported from legacy forums. Posted by Richard (had 276 views)

    User (Old forums)
    Member
    Post count: 23064

    Agreed…

    cell.DataContext is a neat little trick to throw into a
    RoutedEventHandler(OnCellPreviewMouseDown) to make that DataRow the SelectedItem for the Grid BEFORE executing the Click event on e.g. a Button in a GridRow.

    DataSourceItem l_DataSourceItem = cell.DataContext as DataSourceItem;
    this.MyGrid.SelectedItem = l_DataSourceItem;

    Imported from legacy forums. Posted by Desmond (had 4198 views)

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