This is a migrated thread and some comments may be shown as answers.

Custom Validation when pasting from Excel

1 Answer 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 20 Oct 2011, 07:35 PM
I am pasting data from Excel into a radGridView object and would like to do some custom validation from the PastingCellClipboardContent Event.

I have an object of type Widget which implements INotifyPropertyChanged.  It has the following member variables:

- String Type
- String PartNum
- Double Cost

When pasting in the data, I need to check that the PartNum for a Widget is valid based on the Type.  So I have a WCF Service setup that uses a query to return information for a PartNum using the Type.

In PastingCellClipboardContent I am doing the following...

void rgvBulkEntry_PastingCellClipboardContent(Object sender, GridViewCellClipboardEventArgs e)
{
GridViewCellInfo cellInfo = e.Cell as GridViewCellInfo;
Widget Row = cellInfo.Item as Widget;

WebService.ValidatePartNum(Row.Type);


Cell.Value = PartNumLookupValue;
}


private void WebService_ValidatePartNumCompleted(Object sender, ValidatePartNumCompletedEventArgs e)
{
if (e.Result == null)
{
                PartNumLookupValue = "NONE";
}
else
{
                PartNumLookupValue = e.Result;
}
}

However, when debugging the code... Row.Type is null so the lookup done in ValidatePartNum returns nothing, even though the Type cell displays a valid value on the Grid after all validation is complete.  Furthermore, I would expect the PartNum field to display "NONE", but it shows whatever the information copy/pasted from Excel contained.

Any ideas what I'm doing wrong?

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 24 Oct 2011, 09:58 AM
Hello Matthew,

 I am a not sure that I understand you the right way. When pasting a cell value, then in the e.Cell is the information about the cell over which we paste(e.Cell includes the information before the pasting). The value that is currently being pasted is inside e.Value. 
 
As I understand when the original Row.Type is null, then you would like to set the Row.PartNum to be "None". For that purpose you would better change the Data object, not the Visual object (the cell):

Row.PartNum = PartNumLookupValue;

I hope that this will solve your problem.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Matthew
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or