M
Mortos
Hi Gurus,
This has been doing my head in so I've come the you guys.
I have 2 DataGrids using a DataViewManager to source their data. They
are linked via a DataRelation which basically creates a Parent-Child
relation between the 2 grids.
Now I would like to prevent the deletion of any parent row that has
child rows. I have gone down the route of using a 'ForeinKeyConstraint'.
(For all the good that did.) Any I set the DeleteRule to 'None' to stop
said deletion. However, I kept on getting an 'untrappable' exception
(InvalidConstraintException) that always brought everything down
whenever a parent row is deleted.
OK plan B. Forget the use of constraints. Let's do it manually. So i set
up a RowDeleted event (This does not run on the RowDeleting event.) on
the underlying DataTable of the parent grid and try
"e.Row.RejectChanges()" from there and it seems to work except one
problem. The DataGrid is not showing the 'undeleted' (or rejected) row
so I need to force the refreshing of the 'CurrencyManager' as in
//(tgtGrid = TargetDataGrid)
CurrencyManager currMgr =
(CurrencyManager)this.BindingContext[tgtGrid.DataSource,
tgtGrid.DataMember];
currMgr.Refresh();
When run from a 'Refresh' button all rows are displayed. However, I want
the 'Grid Refresh' done 'automagically' when the row delete is aborted
in code.
Any Ideas people? I can't really dedicate more time to finishing the
module until I know there is light at the end of this tunnel ;-)
This has been doing my head in so I've come the you guys.
I have 2 DataGrids using a DataViewManager to source their data. They
are linked via a DataRelation which basically creates a Parent-Child
relation between the 2 grids.
Now I would like to prevent the deletion of any parent row that has
child rows. I have gone down the route of using a 'ForeinKeyConstraint'.
(For all the good that did.) Any I set the DeleteRule to 'None' to stop
said deletion. However, I kept on getting an 'untrappable' exception
(InvalidConstraintException) that always brought everything down
whenever a parent row is deleted.
OK plan B. Forget the use of constraints. Let's do it manually. So i set
up a RowDeleted event (This does not run on the RowDeleting event.) on
the underlying DataTable of the parent grid and try
"e.Row.RejectChanges()" from there and it seems to work except one
problem. The DataGrid is not showing the 'undeleted' (or rejected) row
so I need to force the refreshing of the 'CurrencyManager' as in
//(tgtGrid = TargetDataGrid)
CurrencyManager currMgr =
(CurrencyManager)this.BindingContext[tgtGrid.DataSource,
tgtGrid.DataMember];
currMgr.Refresh();
When run from a 'Refresh' button all rows are displayed. However, I want
the 'Grid Refresh' done 'automagically' when the row delete is aborted
in code.
Any Ideas people? I can't really dedicate more time to finishing the
module until I know there is light at the end of this tunnel ;-)