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
250
Selected Item?
posted

List<Employee> employees = Service.GetEmployees();

xamDataGrid1.DataSource = employees;

 

 How can I get  the selected item in terms of an Employee object.. the docs only mention get the selected row and then retrieving stuff via cell values...

 

 Found solution:

PersonEntity selectedPerson = ((Infragistics.Windows.DataPresenter.DataRecord)(xamDataGrid1.SelectedItems.Records[0])).DataItem as PersonEntity;

  • 4850
    Offline posted

    Note that selection and activation are 2 separate concepts in the XamDataGrid. You can have 0 or more selected records at any time but there is only ever 1 active record.

    If you are interested in the selected records then the solution you describe should work. If you want the active record then do this:

    PersonEntity pe = null; 

    DataRecord dr = XamDataGrid1.ActiveRecord as DataRecord;

    if ( dr != null ) pe = rd.DataItem as PersonEntity;

    etc.

    Note: the reason that you need to cast to a DataRecord is because ActiveRecord returns the Record base class since it could also be an instance of a GroupByRecord or an ExpandableFieldRecord.