Class Property tied to GridViewComboBoxColumn not being set during PastingCellClipboardContent Event

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

    Posted 13 Nov 2011 Link to this post

    I have 2 GridViewComboBoxColumns in a radGridView which are bound via ItemsSourceBinding to a List of custom objects.  When copying/pasting data from Excel, all fields are being correctly set to the appropriate values with the exception of the fields linked to the ComboBoxColumns.

    The grid is being initialized with a "BillingItem" object, which contains properties SLA (String) and AvailableSLAs (List<SLA>).

    The GridViewComboBoxColumn DataMemberBinding is set to the BillingItem.SLA, while the ItemsSourceBinding is set to the BillingItem.AvailableSLAs.

    XAML
    <telerik:RadGridView Name="rgvProductLines" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" CanUserFreezeColumns="False" CanUserReorderColumns="False" SelectionMode="Extended" ShowGroupPanel="False" RowDetailsVisibilityMode="Visible" IsFilteringAllowed="False" EditTriggers="CellClick" Height="510" Width="1160" MinHeight="510"  MinWidth="1160" ShowInsertRow="True" CanUserSortColumns="False" AutoGenerateColumns="False">
       <telerik:RadGridView.Columns>
          <telerik:GridViewComboBoxColumn UniqueName="SLA" Header="SLA" DataMemberBinding="{Binding SLA, Mode=TwoWay, ValidatesOnExceptions=True}" ItemsSourceBinding="{Binding AvailableSLAs}" SelectedValueMemberPath="Number" DisplayMemberPath="Description" />
    <telerik:GridViewComboBoxColumn UniqueName="Obligation" Header="Obligation" DataMemberBinding="{Binding Obligation, Mode=TwoWay, ValidatesOnExceptions=True}" ItemsSourceBinding="{Binding AvailableObligations}"  SelectedValueMemberPath="Number" DisplayMemberPath="Number" />
          <!--other fields that are not relevant-->
       </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    During the PastingCellClipboardContent event for the SLA field of each Row being pasted in, the AvailableSLA is being set to an appropriate list of SLA objects.  The SLA field is then being set to "Cell.Value.ToString().Trim()" in order to remove any extra spaces that the Excel data may contain so that it can find a match properly.

    When debugging the code, the AvailableSLA field contains the 2 or 3 SLA objects that it should.  However, the SLA field is initially being set to the correct value when stepping through line by line, but then is being set to Null afterwards by some other process (even though no other code updates in my project sets a value to the SLA property).

    Please help!
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 14 Nov 2011 Link to this post

    Hello Matthew,

    Would you share the implementation of your PastingCellClipboardContent event ? How do you set the value for the property of GridViewComboBoxColumn ? Does the source of the column contain the value you want to set on pasting ? 
     

    Greetings,
    Maya
    the Telerik team

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

  3. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 14 Nov 2011 Link to this post

    void rgvProductLines_PastingCellClipboardContent(Object sender, GridViewCellClipboardEventArgs e)
            {
                // Get Current Record (Row)
                agBillingItem Row = cellInfo.Item as agBillingItem;
     
                // Determine Cell Currently Being Pasted
                switch (e.Cell.Column.UniqueName)
                {
                    String TempString = "";
     
                    case "SLA":
                        // Check for Length Error
                        if (e.Value.ToString().Trim().Length > 20)
                        {
                                TempString = TempString.Substring(0, 20).Trim();
                        }
     
                         Row.AvailableSLAs = SLAs // Page level variable (List<SLA> that contains AvailableSLAs to use for ItemsSourceBinding
     
                        Row.SLA = TempString
                        // Cell.Value = TempString; (I have tried this also with no success)
                        break;
                    // similar case statements with trimming done for other fields pasted in from Excel...
                }
    }
  4. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 14 Nov 2011 Link to this post

    So the value of the property is being set directly via Row.SLA = TempString (TempString containing the original Cell.Value just being trimmed to make sur no extra leading or trailing spaces cause any problems).

    The source of the column (List<SLA> objects) contains for this test scenario 2 items:

    1) Val = "104FSC110110000", Name = "Rejects and Adjustments"
    2) Val = "104FSC180110000", Name = "Other"

    The data being pasted in from Excel matches option #1 above ("104FSC110110000")

    The AvailableSLA property is being set correctly and contains the 2 options, however the SLA property ends up as Null.
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 14 Nov 2011 Link to this post

    Hi Matthew,

    I have tested the behavior in our demos, but still I was not able to reproduce the same issue. Once I pasted a value into an item (the value must be present in the source of the column), it is updated right away. Would you verify whether the setter of the SLA property of your item is called and the value is updated properly at this time ?    

    Regards,
    Maya
    the Telerik team

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

  6. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 14 Nov 2011 Link to this post

    The SLA and AvailableSLA values are being set properly, I stepped through the code to confirm this.  But then the GetErrors method (from implementing INotifyDataErrorInfo) runs for the AvailableSLAs property (finding no errors), but somehow triggers the Set for the SLA property to switch it back to null.

    Is there an event that Is run after the entire Row has been pasted in, like RowValidating or something that may be causing this?
  7. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 14 Nov 2011 Link to this post

    After further debugging (F1 to Step Into each line that executes) I have some clarifications to make to the reply above...

    The SLA and AvailableSLA values are persisted correctly at first.  Then it seems like the Row is displayed and the AvailableSLA values are requested (using "Get" to presumably use as reference for the items in the dropdown).

    It then does the GetErrors check, finds no errors, and then proceeds to set SLA to null.

    It's weird and I'm really not sure why this is happening.
  8. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 14 Nov 2011 Link to this post

    Strangely enough, changing the XAML for the GridViewComboBoxColumn DisplayMemberPath from...

    SelectedValueMemberPath="Number" DisplayMemberPath="Description"

    ...to...

    SelectedValueMemberPath
    ="Number" DisplayMemberPath="Number"

    ...it started showing the values for the SLA column.  This is not ideal to display the numeric code instead of the text description, but will work as a workaround for the time being.

    However, if the SLA values is not a valid option from the AvailableSLAs List, the 1st item in the ComboBox is being displayed (in fact, the SLA property is set to the value of the 1st item in the ComboBox.

    I need this to display as blank or show the field framed in red to identify an error.

    I tried setting SLA = "" if the value does not exist in the AvailableSLAs List, but this did not make any difference.
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 15 Nov 2011 Link to this post

    Hi Matthew,

    It would be great if you could send a sample project illustrating your exact settings and implementation. Thus I would be able to suggest an appropriate solution, not just guessing for one. 
    Thank you in advance for your cooperation.
     

    Best wishes,
    Maya
    the Telerik team

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

  10. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 15 Nov 2011 Link to this post

    Hi Maya,

    Please email me at mdecap@arcticit.com so that I can send you a zipped version of my project.
  11. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 15 Nov 2011 Link to this post

    I will post another code snippet here for the time being until I have you email address to send the zipped project to.

    This function is called during the 

    void rgvProductLines_PastingCellClipboardContent(Object sender, GridViewCellClipboardEventArgs e)
            {
                // Get Current Record (Row)
                GridViewCellInfo cellInfo = e.Cell as GridViewCellInfo;
                agBillingItem Row = cellInfo.Item as agBillingItem;

                // Determine Cell Currently Being Pasted
                switch (cellInfo.Column.UniqueName)
                {
                    case "SLA":
                        // Cleanse SLA
                        CleanseSLA(e, Row);
                        break;
    }
    }

    public void CleanseSLA(GridViewCellClipboardEventArgs Cell, agBillingItem Row)
            {
                // Create Objects
                Boolean MatchFound = false;
                String TempString = Cell.Value.ToString().Trim();
     
                // Check for Length Error
                if (TempString.Length > SLALength)
                {
                    // Trim
                    TempString = TempString.Substring(0, SLALength).Trim();
                }
     
                // Filter SLAs
                FilterSLAs(Row);
     
                // Loop through AvailableSLAs
                //TODO: Not setting invalid SLA to blank
                foreach (agSLA sla in Row.AvailableSLAs)
                {
                    // Check if SLA is in AvailableSLA List
                    if (TempString == sla.Number)
                    {
                        // Update Value
                        Row.SLA = TempString;
     
                        // Update Flag
                        MatchFound = true;
                    }
                }
     
                // Check for Match
                if (MatchFound != true)
                {
                    // Reset SLA Field
                    Row.SLA = "";
                }
    }

    I am checking to see if the Cell.Value being pasted in (trimmed) exists in the AvailableSLAs List.

    I added some additional code to set the Row.SLA = "" in an attempt to have the GridViewComboBoxColumn for the row to dispaly blank (ie not match was found).  I also tried to set Cell.Value = "", but this had the same result.

    The result being that the SLA field is set to "", but the SLA is being set to the 1st item in the ComboBox after the Row pasting is completed.
  12. Matthew
    Matthew avatar
    46 posts
    Member since:
    Aug 2011

    Posted 16 Nov 2011 Link to this post

    After again testing by updating the Row.SLA value using Cell.Value = "" this is now working.
Back to Top