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

How can I catch exception thrown by pasting invalid data to GGC?

Hi,

I have a gridGroupingControl which uses a custom collection as its datasource. If i copy and paste some invalid data into the grid, the application crashes. Attached is the call stack generated when the application crashes. Looks like it dies in the GridCellModelBase.ApplyFormattedText method call.
(please see the attached file.)

Can you please tell me how I can catch the exception so that I can handle it gracefully?

Thanks,

Frank

PasteCrashCallStack.zip

4 Replies

AD Administrator Syncfusion Team March 8, 2007 10:20 PM UTC

Hi Frank,

Try handling the PasteCelltext event. This is raised cell by cell as the text is being pasted. You can validate the text before grid tries to do the past on that cell. You have the option of canceling the single cell paste or cancelly the rest of the paste as well.

this.gridGroupingControl1.TableModel.PasteCellText += new GridPasteCellTextEventHandler(TableModel_PasteCellText);

void TableModel_PasteCellText(object sender, GridPasteCellTextEventArgs e)
{
//try setting e.Cancel to TRUE for the invalid entries
}

Best regards,
Haneef


AD Administrator Syncfusion Team March 9, 2007 03:38 PM UTC

Thanks for your reply. But I don't want to validate the text myself. I would like to have the grid validate the data for me and throw an exception if not valid. In this case, I just want to be able to catch that exception so that it doesn't crash the application.
Thanks,
Frank

>Hi Frank,

Try handling the PasteCelltext event. This is raised cell by cell as the text is being pasted. You can validate the text before grid tries to do the past on that cell. You have the option of canceling the single cell paste or cancelly the rest of the paste as well.

this.gridGroupingControl1.TableModel.PasteCellText += new GridPasteCellTextEventHandler(TableModel_PasteCellText);

void TableModel_PasteCellText(object sender, GridPasteCellTextEventArgs e)
{
//try setting e.Cancel to TRUE for the invalid entries
}

Best regards,
Haneef


AD Administrator Syncfusion Team March 9, 2007 06:25 PM UTC

Hi Frank,

You subscribe the PastCellText event in a GridTableModel and catch the exception during the pasting by calling the e.Style.ApplyFormattedText method in try catch statement. Here is a code snippet to show this.

private void TableModel_PasteCellText(object sender, GridPasteCellTextEventArgs e)
{
try
{
e.Style.ApplyFormattedText(e.Text, GridCellBaseTextInfo.PasteText);
}
catch(Exception ex) //Invalid entry.
{
e.Cancel = true;
}
}

Best regards,
Haneef


AD Administrator Syncfusion Team March 9, 2007 08:31 PM UTC

That works great. Thanks.

Loader.
Live Chat Icon For mobile
Up arrow icon