IDataGridView.SetDataSet

Syntax

SetDataSet(Value: IDatasetModel; AutoFillColumns: Boolean);

Parameters

Value. Relational repository data source, which data should be displayed in the component.

AutoFillColumns. Indicates whether all data source fields are added automatically to component columns.

Description

The SetDataSet method sets a relational data source for the component.

Comments

The following repository objects can be used as data sources for the component in the Value parameter: Query, Table, View, External Table.

After executing the method, columns will be created for each data source field in the Columns collection. If the AutoFillColumns parameter is set to True, default settings will be determined for columns, and they will be displayed in the component. If the parameter is set to False, one will need to set in the application code visibility and settings for the columns that should be displayed in the component.

Example

Executing the example requires that the repository contains a web form with the T_DATA identifier. The table contains a field with the ID identifier. The web form contains the Button1 button and the DataGridView component named DataGridView1.

Add links to the DB, Express, Metabase, Tab, WebForms system assemblies.

Class TESTWebForm: WebForm
    Button1: WebButton;
    DataGridView1: WebDataGridView;

    Sub Button1OnClick;
    Var
        Mb: IMetabase;
        DGView: IDataGridView;
        Sorts: ISortSettings;
        Sort: ISortSetting;
        ExecSettings: IExecuteSettings;
    Begin
        Mb := MetabaseClass.Active;
        DGView := DataGridView1.DataGridView;
        // Change source
        DGView.SetDataSet(Mb.ItemById("T_DATA").Bind As IDatasetModel, True);
        DGView.BeginUpdate;
        // Data displaying settings
        ExecSettings := DGView.ExecuteSettings;
        ExecSettings.AllowPaging := True;
        ExecSettings.CurrentPage := 1;
        ExecSettings.RecordsCount := 10;
        ExecSettings.RecordsLimit := 1000;
        // Sorting settings
        DGView.EnableSort := True;
        Sorts := DGView.SortSettings;
        Sort := Sorts.Add(DGView.Columns.Item(0));
        Sort.SortDirectionType := SortDirection.Ascending;
        Debug.WriteLine("Sorting by field: " + Sort.FieldId);
        // Examples of  filtering conditions
        DGView.Expression.AsString := "(({id}>=100) and ({id}<=1000))";
        DGView.Expression.AsString := "({client_name}=""Petrov"")";
        DGView.Expression.AsString := "({product_name}="""")";
        DGView.Expression.AsString := "({product_name} <> NULL)";
        DGView.EndUpdate;
    End Sub Button1OnClick;
End Class TESTWebForm;

After executing the example, the data source is connected to the DataGridView1 web form component. Data source displaying settings will be determined, sorting by the first column will be set, and data filtering expressions will be determined.

See also:

IDataGridView