InvalidCastException when calling GetPropertyAccessProvider().SetValue?

Whenever i call GetPropertyAccessProvider().SetValue i get an InvalidCastException: Specified cast is not valid

using version wpf syncfusion 18.1.0.42

Note: i attached a sample project to reproduce the issue.


Attachment: SampleApp_e8159bbd.zip

1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team August 25, 2020 02:22 AM UTC

Hi Joseph,

Thank you for contacting Syncfusion support.

Based on provided information we have checked the provided sample. In your underline property of Amount is declared in Decimal type. In Set value defined the value normally it considers as integer. So, Invalid Cast Exception occurs. You can resolve the issue by type case value or declared the underline property as integer. Please refer the below code snippet,

Type case Value c# Code snippet:
 
public class OrderLine 
    { 
        public int ID { get; set; } 
        public string Product { get; set; } 
        public double Quantity { get; set; } 
        public decimal Amount { get; set; } 
    } 
 
 
private void DataGrid_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs e) 
{  
                  //TypeCast the Valuebased on under line collection type               dataGrid.View.GetPropertyAccessProvider().SetValue(e.Record,nameof(OrderLine.Amount),(decimal)9999); 
} 


Change the Underline property type C# Code snippet:
 
public class OrderLine 
{ 
        public int ID { get; set; } 
        public string Product { get; set; } 
        public double Quantity { get; set; } 
        //Change the Underline collection type as integer 
        public int Amount { get; set; } 
} 
 
 
private void DataGrid_CurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs e) 
{  
            dataGrid.View.GetPropertyAccessProvider().SetValue(e.Record, nameof(OrderLine.Amount), 9999); 
} 
 
Sample Link: https://www.syncfusion.com/downloads/support/forum/157177/ze/Modifiedtheprovidesample-979422975

We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Marked as answer
Loader.
Up arrow icon