I've got a strongly typed dataset with three tables. Call them parent,
child, and grandchild. There are relationships between parent and child,
and between child and grandchild, using fields parentId and childId
respectively. parentId and childId are autoincrement, with seed = 0 and
step = -1.
On a form I've got a DataGrid (with the most important fields) and some
textboxes (with more details) at each level. That is:
dgParent.DataSource = ds
dgParent.DataMember = Parent
dgChild.DataSource = ds
dgChild.DataMember = Parent.Parent_Child
dgGrandchild.DataSource = ds
dgGrandchild.DataMember = Parent.Parent_Child.Child_Grandchild
txtParentDetail.DataBindings.Add(New Binding("Text", ds, _
"Parent.ParentDetail"))
txtChildDetail.DataBindings.Add(New Binding("Text", ds, _
"Parent.Parent_Child.ChildDetail"))
txtGrandchildDetail.DataBindings.Add(New Binding("Text", ds, _
"Parent.Parent_Child.Child_Grandchild.GrandchildDetail"))
Viewing data from the database, everything is cool. I can change existing
data and update it fine. I can create new grandchildren. The problem
arises when I click in the last (empty) row of the Child DataGrid, wanting
to create a new Child of the current parent. I enter some data, tab to the
next field, and the data I entered vanishes.
Furthermore, the Child-level textboxes continue to display the data of the
last Child record I was looking at (before I clicked into the last row of
the Child DataSet). I expected them become blank, showing that data has not
yet been entered for the new Child row.
Thinking perhaps the Child DataGrid and Child textboxes had somehow got
different CurrencyManagers. I took a look at this:
BindingContext(dgChild.DataSource, dgChild.DataMember) Is _
txtChildDetail.DataBindings("Text").BindingManagerBase.
But it was true, which I think is as it should be.
Then I put some code into the dgChild's CurrentCellChanged event, to display
the DataGrid's current row and the CurrencyManager's position in the status
bar.
MyStatBarPanel.Text = "DG: " & dgTktGrp.CurrentRowIndex.ToString & _
" CM: " & BindingContext(dgTktGrp.DataSource, _
dgTktGrp.DataMember).Position.ToString
What I found here was that the DataGrid's CurrentRowIndex and the
CurrencyManager's Position were always the same as each other, which is
good. BUT, neither of them changed when I clicked into the last (empty) row
of the DataGrid. Which doesn't seem right, does it?
If anyone can explain either (a) what I might be doing wrong to cause this
oddness or (b) why this behavior is perfectly natural and what is the proper
way to add new records at the Child level, I will be very grateful.
Thomas Berg