Back to Devexpress

ObjectDataSourceValidationService Class

windowsforms-devexpress-dot-xtraspreadsheet-dot-services.md

latest4.5 KB
Original Source

ObjectDataSourceValidationService Class

Default service that validates the ObjectDataSource data sources before using them in the document.

Namespace : DevExpress.XtraSpreadsheet.Services

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public class ObjectDataSourceValidationService :
    IObjectDataSourceValidationService
vb
Public Class ObjectDataSourceValidationService
    Implements 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 service. However, you can implement your own IObjectDataSourceValidationService service and replace the default service. A custom service can be also registered for the non-visual Workbook instance, which has no default service.

Example

csharp
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 load data.
            // Clear the DataSource and DataMember properties to prohibit loading.
            foreach (ObjectDataSource ds in dataSources) {
                ds.DataSource = null;
                ds.DataMember = null;
            };
        }
    }
vb
Imports DevExpress.DataAccess.ObjectBinding
Imports DevExpress.XtraSpreadsheet.Services
            If barCheckCustomValidationService.Checked Then
                spreadsheetControl1.ReplaceService(Of IObjectDataSourceValidationService)(New MyObjectDataSourceValidationService())
            Else
                spreadsheetControl1.ReplaceService(Of IObjectDataSourceValidationService)(New ObjectDataSourceValidationService(spreadsheetControl1))
            End If
    Public Class MyObjectDataSourceValidationService
        Implements IObjectDataSourceValidationService

        Public Sub Validate(ByVal dataSources As IEnumerable(Of ObjectDataSource)) Implements IObjectDataSourceValidationService.Validate
            ' Do nothing to load data.
            ' Clear the DataSource and DataMember properties to prohibit loading.
            For Each ds As ObjectDataSource In dataSources
                ds.DataSource = Nothing
                ds.DataMember = Nothing
            Next ds
        End Sub
    End Class

Inheritance

Object ObjectDataSourceValidationService

See Also

ObjectDataSourceValidationService Members

DevExpress.XtraSpreadsheet.Services Namespace