System.Data Namespace DataTable Class
Returns a customized view of the table which may include a filtered view, or a cursor position.
Script |
[ DataView variable = ] DataTable.DefaultView |
The property is read only with no default value.
The DefaultView property returns a DataView you can use to sort, filter, and search a DataTable.
The following example sets a property of the DataTable object's DataView through the DefaultView property. The example also shows the binding of a DataGrid control to a DataTable named "Suppliers" that includes a column named "CompanyName".
Private void DefaultViewDemo ( ) {
DataTable myDataTable = new DataTable ( );
// insert code to populate a DataTable with data.
// bind grid to DataTable.
myDataGrid.DataSource = myDataTable;
}
private void ChangeRowFilter ( ) {
DataTable gridTable = ( DataTable ) myDataGrid.DataSource;
// set the RowFilter to display a company names that begin with A through I..
gridTable.DefaultView.RowFilter = "CompanyName <= 'I'";
}
Private Sub DefaultViewDemo ( )
Dim myDataTable As New DataTable
' insert code to populate a DataTable with data.
' bind DataGrid to DataTable
myDataGrid.DataSource = myDataTable
End Sub
Private Sub ChangeRowFilter ( )
Dim gridTable As DataTable = CType ( myDataGrid.DataSource, DataTable )
' set the RowFilter to display a company names that begin with A through I.
gridTable.DefaultView.RowFilter = "CompanyName <= 'I'"
End Sub |
|
C# |
VB |
DataTable Members