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

Update Observable Collection Doesn't Change Virtual Property

1 Answer 27 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 1
Joshua asked on 13 Nov 2011, 09:17 PM

Here's the scenario:

I have two controls: MainApp.xaml and a Popup.xaml (that contains a Silverlight popup control)

The MainApp.xaml has a Telerik Grid control (and I don't think this is Telerik specific) that binds to an ObservableCollection in the ViewModel. The ObservableCollection, as defined in the Model, has a few fields as defined below:

public class ProofOfPurchase
{
private ChecksService.ProofOfPurchase _proofOfPurchase;
public ChecksService.ProofOfPurchase Data
{
get
{
return _proofOfPurchase;
}
set
{
_proofOfPurchase = value;
}
}
public string Name
{
get
{
if (_proofOfPurchase.DebitRequest != null)
return _proofOfPurchase.DebitRequest.Consumer.Contact.FirstName + " " + _proofOfPurchase.DebitRequest.Consumer.Contact.LastName;
else
return string.Empty;
}
}
public string Source
{
get
{
return Enum.GetName(typeof(Enums.ProofOfPurchaseSourceEnum), _proofOfPurchase.SourceEnumId);
}
}
public string HoldCode
{
get
{
if (!string.IsNullOrEmpty(_proofOfPurchase.HoldCode) && (Convert.ToInt32(_proofOfPurchase.HoldCode) > 0))
{
HoldCodes code = POPViewModel.HoldCodes.Where(h => h.CodeId.ToString() == _proofOfPurchase.HoldCode).Single();
return code.CodeId + " - " + code.Code;
}
else
return string.Empty;
}
}
}

The Data property is based on a WCF service. The other three properties are virtual properties for the view.

My grid columns look something like this (this is an extracted sample):

<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Data.Id}" Header="POP ID" UniqueName="POPIP" IsFilterable="False" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Data.DateSubmitted}" Header="Date Submitted" TextAlignment="Right" DataFormatString="M/dd/yyyy" UniqueName="DateSubmitted" IsFilterable="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Data.ProofOfPurchaseStatus.Name}" Header="Status" UniqueName="Status" IsFilterable="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=HoldCode}" Header="Hold Code" UniqueName="HoldCode" IsFilterable="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Source}" Header="Source" UniqueName="Source" IsFilterable="True" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Name}" Header="Pet Owner Name" UniqueName="OwnerName" IsFilterable="False" />

My problem is this:

In this popup, I'm able to change certain fields - ProofOfPurchaseStatus (column 3), Hold Code (column 4), and Source (column 5) being some of them. If I update the Status in the popup, the Grid is updated with the new status accordingly. However, if I update the HoldCode or the Source, the Grid view is not updated. The database is updated correctly, but the view, itself, isn't. I have to refresh my page to see the updated grid. Now, if I change the Hold Code Binding Path (column 4) to "Data.HoldCode" to see the underlying, non-calculated data of the field, the column's value is updated every time in the view. Only, when I'm using virtual properties does the view not realize there's a change.

NOTE: I also tried creating a separate method in the Model that executes in the Data property's Setter. The method would update all three virtuals. The virtuals, in this case, only returned private properties (i.e. the calculations were performed in the private method and the virtuals only returned values created/stored by the private method).

What am I missing? It seems like the View (and/or Grid) doesn't know that the virtual properties have changed even though the underlying data object has.

Thanks,
Joshua

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 14 Nov 2011, 09:38 AM
Hi Joshua,

 From the code that you send, I see that you did not implement the INotifyPropertyChanged interface. This is necessary if you want the view to know about any changes in the properties of the bound object. You can use Teleriks implementation - ViewModelBase, and the OnPropertyChanged method. If you still have any questions you have tried this, feel free to contact us again.

Regards,
Nikolay Vasilev
the Telerik team

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

Tags
GridView
Asked by
Joshua
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or