Skip to main content
All docs
V25.1
  • VirtualSourceBase.KeyProperty Property

    Gets or sets a name of key field. The virtual source uses this field to reload specific rows and find the selected row after refresh.

    Namespace: DevExpress.Xpf.Data

    Assembly: DevExpress.Xpf.Core.v25.1.dll

    NuGet Package: DevExpress.Wpf.Core

    Declaration

    public string KeyProperty { get; set; }

    Property Value

    Type Description
    String

    A name of key field.

    Remarks

    Reload Individual Rows

    Use the InfiniteAsyncSource.ReloadRows / PagedAsyncSource.ReloadRows method to update individual rows.

    private void Button_Click(object sender, RoutedEventArgs e) {
        int[] selectedRowIds = grid.SelectedItems.Cast<IssueData>().Select(x => x.Id).ToArray();
        ((InfiniteAsyncSource)(grid.ItemsSource)).ReloadRows(selectedRowIds);
    }  
    

    Specify the KeyProperty property to allow a virtual source to construct a filter with an InOperator.

    var source = new InfiniteAsyncSource() {
        ElementType = typeof(IssueData),
        KeyProperty = nameof(IssueData.Id)
    };  
    
    public class IssueData {
        public int Id { get; private set; }
        public string Subject { get; private set; }
        public string User { get; private set; }
        public DateTime Created { get; private set; }
        public int Votes { get; private set; }
        public Priority Priority { get; private set; }
    } 
    

    Retain a Selected Row and Scroll Position After Refresh

    The FetchRowsEventArgsBase.Take property returns the number of rows that should be reloaded. Use this property to allow the InfiniteAsyncSource to retain a selected row and scroll position after refresh. The PagedAsyncSource retains a selected row and scroll position by default.

    If data in your source are changed frequently, you can retain the same selected row after refresh. Specify the KeyProperty property to make a virtual source find the selected row by a specific field:

    var source = new InfiniteAsyncSource() {
        ElementType = typeof(IssueData),
        KeyProperty = nameof(IssueData.Id)
    };  
    
    public class IssueData {
        public int Id { get; private set; }
        public string Subject { get; private set; }
        public string User { get; private set; }
        public DateTime Created { get; private set; }
        public int Votes { get; private set; }
        public Priority Priority { get; private set; }
    } 
    

    The following code snippets (auto-collected from DevExpress Examples) contain references to the KeyProperty 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.

    See Also