Custom Validation when pasting from Excel

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 20 Oct 2011 Link to this post

    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?
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Oct 2011 Link to this post

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

Back to Top