Edit

Share via


DataView Constructors

Definition

Initializes a new instance of the DataView class.

Overloads

DataView()

Initializes a new instance of the DataView class.

DataView(DataTable)

Initializes a new instance of the DataView class with the specified DataTable.

DataView(DataTable, String, String, DataViewRowState)

Initializes a new instance of the DataView class with the specified DataTable, RowFilter, Sort, and DataViewRowState.

DataView()

Source:
DataView.cs
Source:
DataView.cs
Source:
DataView.cs

Initializes a new instance of the DataView class.

C#
public DataView();

Examples

The following example creates a new DataView.

C#
private void MakeDataView()
{
    DataView view = new DataView();

    view.Table = DataSet1.Tables["Suppliers"];
    view.AllowDelete = true;
    view.AllowEdit = true;
    view.AllowNew = true;
    view.RowFilter = "City = 'Berlin'";
    view.RowStateFilter = DataViewRowState.ModifiedCurrent;
    view.Sort = "CompanyName DESC";

    // Simple-bind to a TextBox control
    Text1.DataBindings.Add("Text", view, "CompanyName");
}

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

DataView(DataTable)

Source:
DataView.cs
Source:
DataView.cs
Source:
DataView.cs

Initializes a new instance of the DataView class with the specified DataTable.

C#
public DataView(System.Data.DataTable? table);
C#
public DataView(System.Data.DataTable table);

Parameters

table
DataTable

A DataTable to add to the DataView.

Examples

The following example creates a new DataView with the specified DataTable.

C#
private void MakeDataView()
{
    DataView view = new DataView(DataSet1.Tables["Suppliers"]);

    // Bind a ComboBox control to the DataView.
    Combo1.DataSource = view;
    Combo1.DisplayMember = "Suppliers.CompanyName";
}

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

DataView(DataTable, String, String, DataViewRowState)

Source:
DataView.cs
Source:
DataView.cs
Source:
DataView.cs

Initializes a new instance of the DataView class with the specified DataTable, RowFilter, Sort, and DataViewRowState.

C#
public DataView(System.Data.DataTable table, string? RowFilter, string? Sort, System.Data.DataViewRowState RowState);
C#
public DataView(System.Data.DataTable table, string RowFilter, string Sort, System.Data.DataViewRowState RowState);

Parameters

table
DataTable

A DataTable to add to the DataView.

RowFilter
String

A RowFilter to apply to the DataView.

Sort
String

A Sort to apply to the DataView.

RowState
DataViewRowState

A DataViewRowState to apply to the DataView.

Examples

The following example creates a new DataView with the specified DataTable.

C#
private void MakeDataView(DataSet dataSet)
{
    DataView view = new DataView(dataSet.Tables["Suppliers"],
        "Country = 'UK'", "CompanyName",
        DataViewRowState.CurrentRows);
    view.AllowEdit = true;
    view.AllowNew = true;
    view.AllowDelete = true;
}

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1