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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

57706 Mar 8,2007 09:48 PM UTC Mar 9,2007 08:31 PM UTC WinForms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On March 8, 2007 09:48 PM UTC

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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On 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

Administrator [Syncfusion]
Replied On March 9, 2007 08:31 PM UTC

That works great. Thanks.

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.

Warning Icon 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.Close Icon

;