Skip to main content

IObjectDataSourceValidationService Interface

Allows custom validation of the ObjectDataSource data sources before using them in the document.

Namespace: DevExpress.XtraSpreadsheet.Services

Assembly: DevExpress.Spreadsheet.v23.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

public interface IObjectDataSourceValidationService

Remarks

The ObjectDataSource can cause an undesired behavior when retrieving its data. This may be unacceptable in certain situations. You can use the SpreadsheetControlOptions.DataSourceOptions option to specify whether to prohibit the ObjectDataSource data retrieval, prompt the user or silently load the data. To prompt the user, the WinForms SpreadsheetControl calls the ObjectDataSourceValidationService.Validate method of the default IObjectDataSourceValidationService implementation. However, you can implement your own service with a custom IObjectDataSourceValidationService.Validate method to replace the default service. A custom service can be also registered for the non-visual Workbook instance, which has no default service.

Example

using DevExpress.DataAccess.ObjectBinding;
using DevExpress.XtraSpreadsheet.Services;
            if (barCheckCustomValidationService.Checked) {
                spreadsheetControl1.ReplaceService<IObjectDataSourceValidationService>(new MyObjectDataSourceValidationService());
            }
            else {
                spreadsheetControl1.ReplaceService<IObjectDataSourceValidationService>(new ObjectDataSourceValidationService(spreadsheetControl1));
            }
    public class MyObjectDataSourceValidationService : IObjectDataSourceValidationService {
        public void Validate(IEnumerable<ObjectDataSource> dataSources) {
            // Do nothing to allow the control to load data.
            // Clear the DataSource and DataMember properties to prohibit data loading.
            foreach (ObjectDataSource ds in dataSources) {
                ds.DataSource = null;
                ds.DataMember = null;
            };
        }
    }
See Also