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.
Unfortunately, activation email could not send to your email. Please try again.

exceptions in DBG

Thread ID:

Created:

Updated:

Platform:

Replies:

34022 Aug 31,2005 08:22 AM Aug 31,2005 10:30 AM Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On August 31, 2005 08:22 AM

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

Administrator [Syncfusion]
Replied On August 31, 2005 09:07 AM

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.

Administrator [Syncfusion]
Replied On August 31, 2005 09:32 AM

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?

Administrator [Syncfusion]
Replied On August 31, 2005 10:30 AM

>>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;

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;