All docs
V20.1
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

DataControlBase.RestoreStateOnSourceChange Property

Gets or sets whether to retain the control's select, focus, check, and group states when a new ItemsSource is assigned.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.1.Core.dll

Declaration

public bool RestoreStateOnSourceChange { get; set; }
Public Property RestoreStateOnSourceChange As Boolean

Property Value

Type Description
Boolean

true, to retain the control states; otherwise, false.

Remarks

Use the DataControlBase.RestoreStateKeyFieldName property to specify a key field that is used to compare two objects when the state is restored.

<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>
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 DataControlBase.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.

    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)); }
        }
        public override bool Equals(object obj) {
            Item item = obj as Item;
            if(item == null) return false;
            return item.ID == ID;
        }
        public override int GetHashCode() {
            return ID.GetHashCode();
        }
    } 
    
See Also