Page 1
Visual Studio 2005
Using the DataGridView Control
V. Matos
Cleveland State University
Page 2
2
Create Windows Project: WinDB_Demo_01
Page 3
3
Main menu: Data | Add New Data source …
Page 4
4
Select: Database and click on Next
Page 5
5
Select existing DB connection (or create a new one)
Page 6
6
Save selected connection string
Page 7
7
Choose Database Objects
Page 8
8
You may choose a specific table (instead of ALL of them)
Page 9
9
VB project now contains a local DataSet reflecting the image of selected database objects
Page 10
10
From VB Toolbox drag to the form a DataGridView control
Page 11
11
Choose Data Source from the current Project’s DataSet selection
Page 12
12
After choosing: Department
Page 13
13
Add a BindingNavigator control to allow motion and maintenace on the DataView
Page 14
14
Modify the BindingNavigatorInsert Standard Items
Page 15
15
After adding Standard Itemsclick/delete unwanted icons
Page 16
16
Click on the BindingNavigator control. Modify its Property page (Associate the DEPARTMENTBindingSource with the BindingNavigator)
Page 17
17
Final image of the DataView and its corresponding ToolStrip
Page 18
18
Double-click on the SAVE icon and insert the following VB code
Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
Me.Validate()
If (Me.CompanyDataSet.HasChanges) Then
Me.DEPARTMENTBindingSource.EndEdit()
Me.DEPARTMENTTableAdapter.Update(Me.CompanyDataSet.DEPARTMENT)
End If
End Sub