Let s Try It

Team-Fly team-fly    

 
ADO.NET Programming in Visual Basic .NET
By Steve  Holzner, Bob  Howell

Table of Contents
Chapter 11.   Creating Your Own Data Control


Let's Try It!

If you haven't already done so, set the TestBed project to be the startup project. Now run the program. The DataGrid should populate with the contents of the Northwind Customer table. Try clicking the navigation buttons . The pointer should move accordingly and the caption should update with Record: n of x ( assuming the autoText property is set to True). Notice there is no user -supplied code in the test form. All of this functionality comes from the navigator control (see Figure 11.6).

Figure 11.6. The running test harness.

graphics/11fig06.gif

Click on the Selector column of the grid and move the pointer that way. Oops! The record counter does not get updated. The VB 6 Data Control had the same problem. The control has no way of knowing that you changed the position in the grid. The grid does notify its parent form through the CurrentCellChanged event. We can use this event to notify the navigator control that the user clicked a new row in the grid. As it turns out, the binding context position does change, but the binding context does not notify the form of this. I think there still needs to be some work done to ADO .NET in the next release. So if you add the following code to the DataGrid's CurrentCellChanged event, the caption will update properly:

 Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, _              ByVal e As System.EventArgs) Handles  DataGrid1.CurrentCellChanged  UcDataNav1.Text = "Record: " & _       Me.BindingContext(UcDataNav1).Position + 1 & _       " of " & UcDataNav1.DataTable.Rows.Count  End Sub 

Now if you run the project you will see the caption change when you click on the grid directly. This is great but let's try something else. Try changing something in the grid. Now close the form and run the project again. The value reverted to its old value! Do you remember that we said ADO .NET DataSets are disconnected? When we updated the grid, we changed the data in the underlying DataTable, but we did nothing to change the data in the database itself. Unlike the old ADO Data Control, we will have to add more functionality to make this happen.


Team-Fly team-fly    
Top


ADO. NET Programming in Visual Basic. NET
ADO.NET Programming in Visual Basic .NET (2nd Edition)
ISBN: 0131018817
EAN: 2147483647
Year: 2005
Pages: 123

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net