We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

exceptions in DBG

I have datatable as datasource with constraits. When I try to edit record that does not satisfy constraints I get exception. How to catch this exception? I do not want to loose data edited in form. Here is sample of exception: System.Data.InvalidConstraintException: ForeignKeyConstraint TableDefinitionsParameters requires the child key values (myTable) to exist in the parent table. at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge) at System.Data.DataRow.SetNewRecord(Int32 record) at System.Data.DataRow.EndEdit() at System.Data.DataRow.set_Item(DataColumn column, Object value) at System.Data.DataRowView.SetColumnValue(DataColumn column, Object value) at System.Data.DataColumnPropertyDescriptor.SetValue(Object component, Object value) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) catched at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) in :line 0 System.Data.InvalidConstraintException: ForeignKeyConstraint TableDefinitionsParameters requires the child key values (myTable) to exist in the parent table. at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType, Boolean dontRaiseSaveCellInfoEvent, Boolean copyReferenceOnly) at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType) at Syncfusion.Windows.Forms.Grid.GridModel.ChangeCells(GridRangeInfo range, GridStyleInfo[] cellsInfo, StyleModifyType modifyType) at Syncfusion.Windows.Forms.Grid.GridModel.Syncfusion.Windows.Forms.Grid.IGridVolatileDataContainer.ChangeCell(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridVolatileData.set_Item(Int32 rowIndex, Int32 colIndex, GridStyleInfo value) at Syncfusion.Windows.Forms.Grid.GridStyleInfoIdentity.OnStyleChanged(StyleInfoBase style, StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.SetValue(StyleInfoProperty sip, Object value) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.set_CellValue(Object value) at Syncfusion.Windows.Forms.Grid.GridCellModelBase.ApplyFormattedText(GridStyleInfo style, String text, Int32 textInfo) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.ApplyFormattedText(String text) at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.OnSaveChanges() at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.RaiseSaveChanges() at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) in :line 0

3 Replies

AD Administrator Syncfusion Team August 31, 2005 01:07 PM UTC

You can handle the grid.ValidateFailed event. In your handler, if you set grid.CurrentCell.ErrorMessage to some string, that will be the error string displayed. If you set it to an empty string, then no message will be displayed.


AD Administrator Syncfusion Team August 31, 2005 01:32 PM UTC

OK. I writed this code: dtgParameters.ValidateFailed+=new GridValidateFailedEventHandler(dtgParameters_ValidateFailed); --------- --------- private void dtgParameters_ValidateFailed(object sender, GridValidateFailedEventArgs e) { dtgParameters.CurrentCell.ErrorMessage=""; e.Handled=true; } but I still have the same problem how to prevent exception on the level of calling subroutine that shows form containing grid. I''m doing following: private void dtgParameters_ValidateFailed(object sender, GridValidateFailedEventArgs e) { string s=dtgParameters.CurrentCell.ErrorMessage; dtgParameters.CurrentCell.ErrorMessage=""; dtgParameters.CurrentCell.RejectChanges(); e.Handled=true; s+=Environment.NewLine+"Changes have been rejected"; MessageBox.Show(s); } reject changes and showing message box. Is it possible also to move back to this cell?


AD Administrator Syncfusion Team August 31, 2005 02:30 PM UTC

>>how to prevent exception on the level of calling subroutine The only way I know to prevent the exception is to test for whatever constraints you want before the grid tries to save the row to the DataTable. Once the grid tries to save it, the grid cannot control whether ADO.NET raises a constraint exception. To catch the action before the grid tries to save the changes, try handling the grid.RowLeave event. In your handler, test the current values to see whether they satisfy your contraint. If they do not, then you can set e.Cancel = true;

Loader.
Live Chat Icon For mobile
Up arrow icon