How to bind the Active Record to a Model(Model View ViewModel) with the Infragistics XamDataGrid?
Hello,
You can refer to the following forum thread for one possible implementation:(http://forums.infragistics.com/forums/p/5351/27892.aspx)
<igDP:XamDataGrid.ActiveRecord> <MultiBinding Converter="{StaticResource myConverter}" Mode="TwoWay"> <Binding ElementName="xamDataGrid1"/> <Binding Path="CurrentPerson" Mode="TwoWay" /> </MultiBinding></igDP:XamDataGrid.ActiveRecord>
class DataItemToRecordConverter:IMultiValueConverter{ #region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { DataPresenterBase dataPresenterBase = values[0] as DataPresenterBase; if (dataPresenterBase != null) { Person active = values[1] as Person; if (active != null) { return dataPresenterBase.GetRecordFromDataItem(active, true); } } return null; }
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { return new object[] { null, ((DataRecord)value).DataItem }; } #endregion}
I'm using a MultiValueConverter to bind the ActiveRecord.DataItem to the CurrentPerson property of the ViewModel.
Hope this helps.
Vlad
hi,
i want to bind the whole active record to a property in viewmodel which is of type record.
is it not possible to bind with out converter?
Geetha.
Geetha,
In this case you can use the following line of code:
<igDP:XamDataGrid x:Name="xamDataGrid1" DataSource="{Binding People}" ActiveRecord="{Binding Path=CurrentPerson,Mode=TwoWay}" />
where CurrentPerson is a property of type Record in my ViewModel
Let me know if you have any questions with this matter.
Hi,
As you said we can get the Active record from the "CurrentPerson" property in the ViewModel from the same way..How can we passed value of "CurrentPerson" from viewmodel to View and select the record (ie, How to programatically select the record from Viewmodel?)
Thanks,
Pon
Hello Pon,
Thank you for your post. I have been looking into it and I can say that you have to set the CurrentPerson Property of the ViewModel to an object from the XamDataGrid's DataSource collection, so this object could become active Record in the XamDataGrid. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
Hi Stefan,
Thanks for your reply.
I have done the Active record by below code in the viewmodel
CurrentPerson = XamGridView.Records[activeIndex];
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.