Back to Devexpress

DataControlBase.RestoreStateKeyFieldName Property

wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-8906ea05.md

latest4.6 KB
Original Source

DataControlBase.RestoreStateKeyFieldName Property

Gets or sets a name of key field that is used to compare two objects when the state is restored.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public string RestoreStateKeyFieldName { get; set; }
vb
Public Property RestoreStateKeyFieldName As String

Property Value

TypeDefaultDescription
String""

A key field name.

|

Remarks

Set the DataControlBase.RestoreStateOnSourceChange property to true to retain the control’s select, focus, check, and group states when a new ItemsSource is assigned.

xaml
<dxg:GridControl Name="grid" ItemsSource="{Binding Items}" AutoGenerateColumns="AddNew" SelectionMode="Row" 
                 RestoreStateOnSourceChange="True" RestoreStateKeyFieldName="ID">
    <dxg:GridControl.View>
        <dxg:TableView />
    </dxg:GridControl.View>
</dxg:GridControl>
csharp
public class ViewModel : ViewModelBase {
    public ObservableCollection<Item> Items {
        get { return GetValue<ObservableCollection<Item>>(nameof(Items)); }
        private set { SetValue(value, nameof(Items)); }
    }
}
public class Item : BindableBase {
    public string Name {
        get { return GetValue<string>(nameof(Name)); }
        set { SetValue(value, nameof(Name)); }
    }
    public int ID { 
        get { return GetValue<int>(nameof(ID)); }
        set { SetValue(value, nameof(ID)); }
    }      
    public int GroupID {
        get { return GetValue<int>(nameof(GroupID)); }
        set { SetValue(value, nameof(GroupID)); }
    }
}

Requirements

  • The current and new sources should have the same column sets (the same properties).

  • If the RestoreStateKeyFieldName property is not specified, the GridControl uses the Object.Equals method to compare objects. You should override this method. If you use the TreeListView, override the Object.GetHashCode method additionally.

The following code snippets (auto-collected from DevExpress Examples) contain references to the RestoreStateKeyFieldName property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-implement-crud-operations/CS/CodeBehind/EFCore/LocalData/MainWindow.xaml#L24

xml
<dxg:GridControl x:Name="grid" Grid.Row="1"
                 RestoreStateKeyFieldName="Id" RestoreStateOnSourceChange="True">
    <dxg:GridControl.View>

wpf-data-grid-extend-crud-operations/CS/AsyncCRUDOperations/MainWindow.xaml#L20

xml
</dxb:ToolBarControl>
<dxg:GridControl x:Name="grid" ItemsSource="{Binding ItemsSource}" RestoreStateKeyFieldName="Id" RestoreStateOnSourceChange="True" Grid.Row="1">
    <dxmvvm:Interaction.Behaviors>

See Also

DataControlBase Class

DataControlBase Members

DevExpress.Xpf.Grid Namespace