Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
660
Can I easily bind Selected Item to some DataRow (two-way)?
posted

 Hi

I use the grid to display a hierarchical multi-level data. I bind the selected datarecord to another control. So that control 'displays' DataRow currently selected in xamDataGrid.

Is there a possibility to select a DataRecord in xamDataGrid having a DataRow only? Can SelectedRow be two-way bound to anything?

This is pretty critical for us right now

Thank you 

Parents
No Data
Reply
  • 4850
    Offline posted

    Just for some background, there are 2 concepts regarding records in the xamDataGrid, active and selected. There can be any # of selected records so they are exposed via the grid's SelectedItems.Records collection. There can never be more than 1 active record so the grid exposes an ActiveRecord property.

    Both of these return the Records. Record is the base class for DataRecord, GroupByRecord and ExpandableFieldRecord. In order to get to the underlying data item, in this case the DataRow or DataRowView, you need to cast the Record to a DataRecord which exposes a DataItem property, e.g.

    DataRecord dr = grid.ActiveRecord as DataRecord;

    if (dr != null )

    {

    DataRowView drv = dr.DataItem as DataRowView;

    ...

    }

    If you are setting up a binding in xaml it might look something like this:

    "{Binding Path=ActiveRecord.DataItem.SomeProperty, ElementName=xamDataGrid1}"

    I hope this helps. 

     

     

Children