An example on setting the records to the order from the datasource.
This can be done by calling the RefreshSortPosition method. By default in the first instance the control adds the record at the top, by calling this method in the RecordAdded event handler will match the ordering that is bound to it's data.
XAML:
<Window.DataContext> <my:MainWindowData /></Window.DataContext><Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <igDP:XamDataGrid x:Name="XamDataGrid1" DataSource="{Binding Path=Strings}" RecordAdded="XamDataGrid1_RecordAdded"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AllowAddNew="True" /> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid> <igDP:XamDataGrid x:Name="XamDataGrid2" DataSource="{Binding Path=Strings}" Grid.Column="1"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AllowAddNew="True" /> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid></Grid>
Code-behind:
public partial class MainWindow : Window{ public MainWindow() { InitializeComponent(); } private void XamDataGrid1_RecordAdded(object sender, Infragistics.Windows.DataPresenter.Events.RecordAddedEventArgs e) { e.Record.RefreshSortPosition(); }} public class MainWindowData : INotifyPropertyChanged{ public MainWindowData() { Strings = new ObservableCollection { "bbb", "ccc" }; } public event PropertyChangedEventHandler PropertyChanged = delegate { }; protected void RaisePropertyChanged(string name) { PropertyChanged(this, new PropertyChangedEventArgs(name)); } private ObservableCollection strings; public ObservableCollection Strings { get { return strings; } set { if (strings != value) { strings = value; RaisePropertyChanged("Strings"); } } }}
public partial class MainWindow : Window{
public MainWindow() { InitializeComponent(); }
private void XamDataGrid1_RecordAdded(object sender, Infragistics.Windows.DataPresenter.Events.RecordAddedEventArgs e) { e.Record.RefreshSortPosition(); }}
public class MainWindowData : INotifyPropertyChanged{ public MainWindowData() { Strings = new ObservableCollection { "bbb", "ccc" }; }
public event PropertyChangedEventHandler PropertyChanged = delegate { }; protected void RaisePropertyChanged(string name) { PropertyChanged(this, new PropertyChangedEventArgs(name)); }
private ObservableCollection strings; public ObservableCollection Strings { get { return strings; } set { if (strings != value) { strings = value; RaisePropertyChanged("Strings"); } } }}