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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

57706 Mar 8,2007 04:48 PM Mar 9,2007 03:31 PM Windows Forms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On March 8, 2007 04:48 PM

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 05:20 PM

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 10:38 AM

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 01:25 PM

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 03:31 PM

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.

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.

;