Back to Devexpress

Edit and Update Extracts

dashboard-115930-winforms-dashboard-winforms-designer-create-dashboards-in-the-winforms-designer-providing-data-extract-data-source-editing-and-updating-extracts.md

latest7.3 KB
Original Source

Edit and Update Extracts

  • Dec 15, 2021
  • 3 minutes to read

This topic describes how to edit settings of the created data extract and update its data from the original data source.

Edit a Data Extract

To edit the created or loaded data extract, click the Edit Extract button in the Data Source ribbon tab.

This invokes the Edit Extract form that replicates the functionality of the Data Source wizard for the Extract Data Source.

You can either change the original data source or you can load another data extract from the file.

Update a Data Extract

To update the data extract from the original data source, click the Update button in the Data Source ribbon tab.

In the invoked Confirmation dialog, click Yes to update the extract data or click No to cancel the update process.

Edit an Original Data Source

The Extract Data Source also allows you to change settings of the original data source’s copy. For instance, you can edit connection or query settings for SQL data sources. To do this, use buttons from the Extract Source group in the Data Source ribbon tab.

For other data source types, use the Edit Extract Source button.

Clicking this button invokes the Data Source Wizard specific to the original data source type (for instance, the Excel Data Source or Object Data Source).

Edit and Update the Extract Data Source in Code

ExtractDataSource API

To get access to the original data source, use the ExtractDataSource.ExtractSourceOptions.DataSource property.

To update the extract data source, call the following methods:

MethodDescription
DashboardExtractDataSource.UpdateExtractFileUpdates data in the data extract file.
DashboardViewer.UpdateExtractDataSourcesAsyncUpdates the specified extract data sources in the current dashboard asynchronously. Allows you to set custom actions to perform after updating the data and file.
DashboardDesigner.UpdateExtractDataSourcesAsyncUpdates the specified extract data sources in the current dashboard asynchronously. Allows you to set custom actions to perform after updating the data and file.
DashboardControl.UpdateExtractDataSourcesAsyncUpdates the specified extract data sources in the current dashboard asynchronously. Allows you to specify custom actions to perform after updating the data and file.

View Example: WinForms - Dashboard with Extract Data Source

The following code snippet implements the UpdateExtractAsync method that updates all extract files bound to the dashboard. It displays a message box and reloads DashboardViewer’s data when data is updated, and displays a message box when the extract files are updated.

cs
delegate void SafeUpdate(string file);

private async void UpdateExtractAsync() {
    await dashboardViewer1.UpdateExtractDataSourcesAsync(
        (fileName, result) => { 
            OnDataReady(fileName); 
        },
        (fileName, result) => { 
            MessageBox.Show($"File {fileName} updated "); 
        });
}

void OnDataReady(string fileName) {
    dashboardViewer1.Invoke(new SafeUpdate(UpdateViewer), new object[] { fileName });
}
void UpdateViewer(string fileName) {
    MessageBox.Show($"Data for the file {fileName} is ready ");
    dashboardViewer1.ReloadData();
}
vb
Private Delegate Sub SafeUpdate(ByVal file As String)

Private Sub UpdateExtractAsync()
    dashboardViewer1.UpdateExtractDataSourcesAsync(
        Sub(fileName, result)
            OnDataReady(fileName)
        End Sub,
        Sub(fileName, result)
            MessageBox.Show($"File {fileName} updated ")
        End Sub)
End Sub

Private Sub OnDataReady(ByVal fileName As String)
    dashboardViewer1.Invoke(New SafeUpdate(AddressOf UpdateViewer), New Object() {fileName})
End Sub
Private Sub UpdateViewer(ByVal fileName As String)
    MessageBox.Show($"Data for the file {fileName} is ready ")
    dashboardViewer1.ReloadData()
End Sub

Edit Extract Dialog

To invoke the Edit Extract form, call the ExtractDataSourceUIHelper.EditExtractOptions(DashboardExtractDataSource, EditExtractOptionsContext) method, as illustrated in the following code snippet:

csharp
private void UpdateExtract()
{
    DashboardExtractDataSource extractDS = dashboardViewer1.Dashboard.DataSources[0] as DashboardExtractDataSource;
    if (extractDS != null)
    {
        EditExtractOptionsContext optionsContext = 
            new EditExtractOptionsContext(this.GetActiveLookAndFeel(), this, dashboardViewer1.Dashboard.DataSources);
        ExtractDataSourceUIHelper.EditExtractOptions(extractDS, optionsContext);
    }
    dashboardViewer1.ReloadData();
}
vb
Private Sub UpdateExtract()
    Dim extractDS As DashboardExtractDataSource = TryCast(dashboardViewer1.Dashboard.DataSources(0), DashboardExtractDataSource)
    If extractDS IsNot Nothing Then
        Dim optionsContext As New EditExtractOptionsContext(Me.GetActiveLookAndFeel(), Me, dashboardViewer1.Dashboard.DataSources)
        ExtractDataSourceUIHelper.EditExtractOptions(extractDS, optionsContext)
    End If
    dashboardViewer1.ReloadData()
End Sub