DataTable.DefaultView 属性

定义

获取可能包含筛选视图或游标位置的表的自定义视图。

public:
 property System::Data::DataView ^ DefaultView { System::Data::DataView ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Data.DataView DefaultView { get; }
[System.ComponentModel.Browsable(false)]
[System.Data.DataSysDescription("DataTableDefaultViewDescr")]
public System.Data.DataView DefaultView { get; }
[<System.ComponentModel.Browsable(false)>]
member this.DefaultView : System.Data.DataView
[<System.ComponentModel.Browsable(false)>]
[<System.Data.DataSysDescription("DataTableDefaultViewDescr")>]
member this.DefaultView : System.Data.DataView
Public ReadOnly Property DefaultView As DataView

属性值

DataView 关联的 DataTable

属性

示例

以下示例通过 DefaultView 属性DataTable设置 对象的 DataView 属性。 该示例还演示了控件 DataGridViewDataTable 名为“Suppliers”的绑定,其中包括名为“CompanyName”的列。

private void BindDataGrid()
{
    DataTable table = new DataTable();

    // Insert code to populate a DataTable with data.

    // Bind grid to DataTable.
    dataGrid1.DataSource = table;
}

private void ChangeRowFilter()
{
    DataTable gridTable = (DataTable) dataGrid1.DataSource;

    // Set the RowFilter to display a company names that
    // begin with A through I..
    gridTable.DefaultView.RowFilter = "CompanyName < 'I'";
}
Private Sub BindDataGrid()
   Dim table As New DataTable

   ' Insert code to populate a DataTable with data.

   ' Bind DataGrid to DataTable
   DataGrid1.DataSource = table
End Sub 

Private Sub ChangeRowFilter()
   Dim gridTable As DataTable = _
       CType(dataGrid1.DataSource, DataTable)

   ' Set the RowFilter to display a company names 
   ' that begin with A through I.
   gridTable.DefaultView.RowFilter = "CompanyName < 'I'"
End Sub

注解

属性 DefaultView 返回可用于 DataView 排序、筛选和搜索 的 DataTable

适用于

另请参阅