O'Reilly logo

Visual Basic 2012 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

DATAVIEW

A DataView object represents a customizable view of the data contained in a DataTable. You can use the DataView to select some or all of the DataTable’s data and display it sorted in some manner without affecting the underlying DataTable.

A program can use multiple DataViews to select and order a table’s data in different ways. You can then bind the DataViews to controls such as the DataGrid control to display the different views. If any of the views modifies its data, for example, by adding or deleting a row, the underlying DataTable object’s data is updated and any other views that need to see the change are updated as well.

Example program DataGrids, which is available for download on the book’s website, uses the following code to demonstrate DataViews:

Private Sub Form1_Load() Handles MyBase.Load ' Make a DataTable. Dim contacts_table As New DataTable("Contacts") ' Add columns. contacts_table.Columns.Add("FirstName", GetType(String)) contacts_table.Columns.Add("LastName", GetType(String)) contacts_table.Columns.Add("Street", GetType(String)) contacts_table.Columns.Add("City", GetType(String)) contacts_table.Columns.Add("State", GetType(String)) contacts_table.Columns.Add("Zip", GetType(String)) ' Make the combined FirstName/LastName unique. Dim first_last_columns() As DataColumn = { contacts_table.Columns("FirstName"), contacts_table.Columns("LastName") } contacts_table.Constraints.Add(New UniqueConstraint(first_last_columns)) ' Make some contact data. contacts_table.Rows.Add(New ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required