binder.Current.row.rowstate not reflecting actual state of child row

A

astro

I'm working through the binder stuff trying to get a handle on it...

I have setup a master-detail dataset and have a couple of textboxes from the
master along with a datadgrid for the child data.

I have a navigation pallete with the usual arrows. All arrow btn's are
handled by the same handler.

Before moving off the current record I do the following:

BindingContext(Me.DataSet11, "table2").EndCurrentEdit()

BindingContext(Me.DataSet11, "table1").EndCurrentEdit()

'deal with current row state 1st

checkRowState(sender, e)


CheckRowSTate looks at the rowstate and calls the SaveRecord routnine if
needed.
Select Case mbinder.Current.row.rowstate
Case DataRowState.Added

Call saveRecord()

Case DataRowState.Modified

Call saveRecord()

End Select

Select Case mbinder2.Current.row.rowstate

Case DataRowState.Added

Call saveRecord()

Case DataRowState.Modified

Call saveRecord()

End Select

The problem i'm having is this: after changing a value in the child
(datagrid) description field the rowstate remains unchanged on the 2nd or
greater master record. If I make a change to the child rec on the 1st
master the rowstate is 'modified' as expected.....

at this point i'm just bewildered.............
 
C

Cor Ligthert [MVP]

Astro,

I am afraid that I don't understand your problem, however, a rowstate
reflects only the state of the changed datarow, where it is not important if
this is a child or a master.

To get more answers, I give you the advice to past in next time your code
first in a notebook copy it back and past it in a message. Now it is hard to
see in most newsreaders what your code looks like.

I hope this helps anyhow

Cor
 
A

astro

Thanks Cor -- )

I am trying to trap state changes for a child table on a form when from
'unchanged' to 'modified' or 'added.' The code I am using does not do this.
I will repost it here:

form load:
========
cmT2 = CType(Me.BindingContext(Me.DataSet11.Tables!table2), CurrencyManager)


custom SaveRecord event:
===================

cmT2.EndCurrentEdit()

Select Case cmT2.Current.row.rowstate
Case DataRowState.Added
Stop
Case DataRowState.Modified
Stop
End Select


Before the postion changes on the form's master record, the 'saverecord'
code is called. When I make changes to the datagrid - which is populated by
the 'child' table and linked via the 'datamember' property using the
'table1table2' relation - and then move to another 'parent' record the
saveRecord event is called does not report an 'Added' or 'Modified' state in
the child table.

any ideas?
 
B

Bart Mermuys

Hi,
[inline]

astro said:
Thanks Cor -- )

I am trying to trap state changes for a child table on a form when from
'unchanged' to 'modified' or 'added.' The code I am using does not do
this. I will repost it here:

form load:
========
cmT2 = CType(Me.BindingContext(Me.DataSet11.Tables!table2),
CurrencyManager)

There is a chance you're getting the wrong CurrencyManager and so the wrong
Current DataRowView. You have to use the same DataSource/DataMember that
you used for binding to get the CurrencyManager.

Eg.:
detailGrid.DataSource = DataSet11
detailGrid.DataMember = "master_table.master_to_detail_relation"

cmT2 = DirectCast(BindingContext(DataSet11,
"master_table.master_to_detail_relation"), CurrencyManager)

A more generic way:
cmT2 = DirectCast(BindingContext(detailGrid.DataSource,
detailGrid.DataMember), CurrencyManager)

Also, if your detail table can contain multiple detail rows for each master
row, then you might want to use detailTable.GetChanges() or
detailTable.Select(), because the user could have changed multiple detail
rows before navigating master rows.

HTH,
Greetings
 
A

astro

ahhhhhhhhhhhh - I tried that before in a slighly different syntax and just
missed it.

Thanks !!

Bart Mermuys said:
Hi,
[inline]

astro said:
Thanks Cor -- )

I am trying to trap state changes for a child table on a form when from
'unchanged' to 'modified' or 'added.' The code I am using does not do
this. I will repost it here:

form load:
========
cmT2 = CType(Me.BindingContext(Me.DataSet11.Tables!table2),
CurrencyManager)

There is a chance you're getting the wrong CurrencyManager and so the
wrong
Current DataRowView. You have to use the same DataSource/DataMember that
you used for binding to get the CurrencyManager.

Eg.:
detailGrid.DataSource = DataSet11
detailGrid.DataMember = "master_table.master_to_detail_relation"

cmT2 = DirectCast(BindingContext(DataSet11,
"master_table.master_to_detail_relation"), CurrencyManager)

A more generic way:
cmT2 = DirectCast(BindingContext(detailGrid.DataSource,
detailGrid.DataMember), CurrencyManager)

Also, if your detail table can contain multiple detail rows for each
master
row, then you might want to use detailTable.GetChanges() or
detailTable.Select(), because the user could have changed multiple detail
rows before navigating master rows.

HTH,
Greetings

custom SaveRecord event:
===================

cmT2.EndCurrentEdit()

Select Case cmT2.Current.row.rowstate
Case DataRowState.Added
Stop
Case DataRowState.Modified
Stop
End Select


Before the postion changes on the form's master record, the 'saverecord'
code is called. When I make changes to the datagrid - which is populated
by the 'child' table and linked via the 'datamember' property using the
'table1table2' relation - and then move to another 'parent' record the
saveRecord event is called does not report an 'Added' or 'Modified' state
in the child table.

any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top