Cor, I suppose you turned on "catching the IndexOutOfRangeException", via the
Debug menu, Exceptions, CLR exceptions, System,
System.IndexOutOfRangeException. --> Breaking into the debugger? Otherwise
you'll see only a two sec's delay (only once), but no execute interuption.
I downsized my project, also using a dataset without a dataview, but the
exception is still there, however the remaining code is very basic. I'll
paste it underneath, so maybe you can have a look at it? The form contains
four textboxes (bound to the master table), four navigation buttons, and one
datagrid (detail-rows). A connection is made to the Northwind database
(please modify the connectionstring).
Maybe you see a difference with your testcode?
Regards Coen
--------------------- Start Code: -------------------
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim myConnection As SqlConnection
Dim mDs As New DataSet
Dim mDa1 As SqlDataAdapter
Dim mDa2 As SqlDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
myConnection = New
SqlConnection("server=(local)\INSTANCE01;Trusted_Connection=yes;database=northwind")
mDa1 = New SqlDataAdapter("SELECT * FROM Customers", myConnection)
mDa2 = New SqlDataAdapter("SELECT * FROM orders", myConnection)
'Fill dataset
mDa1.Fill(mDs, "Customers")
mDa2.Fill(mDs, "Orders")
'Define relation
mDs.Relations.Add(New DataRelation( _
relationName:="relCustomersOrders", _
parentColumn:=mDs.Tables("Customers").Columns("CustomerId"), _
childColumn:=mDs.Tables("Orders").Columns("CustomerId"), _
createconstraints:=True))
'Eventhandlers navigatie
Call AddHandlers()
'Some textboxes databinding to the master table
txtCustomerId.DataBindings.Add("Text", mDs.Tables("Customers"),
"CustomerId")
txtCompanyname.DataBindings.Add("Text", mDs.Tables("Customers"),
"CompanyName")
txtContactname.DataBindings.Add("Text", mDs.Tables("Customers"),
"ContactName")
txtPostalcode.DataBindings.Add("Text", mDs.Tables("Customers"),
"PostalCode")
'Bind the datagrid to the detail table via the datarelation
grdOrders.DataSource = mDs.Tables("Customers")
grdOrders.DataMember =
mDs.Tables("Customers").ChildRelations("relCustomersOrders").ToString
grdOrders.ReadOnly = True 'Set the datagrid to READONLY
End Sub
Private Sub AddHandlers()
'Eventhandler navigate-buttons
AddHandler btnFirst.Click, AddressOf Me.Navigate
AddHandler btnNext.Click, AddressOf Me.Navigate
AddHandler btnPrevious.Click, AddressOf Me.Navigate
AddHandler btnLast.Click, AddressOf Me.Navigate
End Sub
Private Sub Navigate(ByVal sender As System.Object, ByVal e As
System.EventArgs)
'grdOrders.ReadOnly = False '--> This line prevents the
IndexOutOfRangeException
With Me.BindingContext(mDs.Tables("Customers"))
Select Case sender.name
Case "btnFirst"
.Position = 0
Case "btnPrevious"
.Position -= 1
Case "btnNext"
.Position += 1
Case "btnLast"
.Position = .Count - 1
End Select
End With
'grdOrders.ReadOnly = True '<-- This line prevents the
IndexOutOfRangeException
End Sub
End Class