I have a RadGridView, whose ItemsSource is an ObservableCollection<X>. Using the example in the demo about attaching a RadContextMenu to each row in the GridView_RowLoaded event handler, I add a context menu. In the OnMenuItemClick, I can get the GridViewRow, and the ObservableCollection<X>, etc.
If the action is delete, then collection.remove((X)row.DataContext) removes the row and the grid reflects this. I have a few other actions on the context menu which change other properties of X, say X.Active = true/false. The corresponding columns in the grid (rendered as a checkbox for X.Active is bool) do not update. However, the collection is definitely changed as the context menu knows what options to enable/disable based on this property (as enabled/disabled in the OnMenuOpened()) handler.
I want to tell the gridview that this row has been changed. I don't want to remove and re-add the row, which does work.
I have spent a while searching for a solution to this with no luck. I admit I am sitll quite new to Silverlight, but not to UIs and there must be a way to have a notification occur when a property changes.
Please advise and Thanks,
Tim
7 Answers, 1 is accepted
Changing properties of an object inside ObservableCollection<T> will not raise CollectionChanged - RadGridView will be refreshed automatically only when on CollectionChanged!
Possible implementation will be to raise explicitly CollectionChanged event on PropertyChanged if these objects are INotifyPropertyChange
Vlad
Thanks for the clue,
Tim
public class X : System.ComponentModel.INotifyPropertyChanged
{
private string _field;
public string Field
{
get { return _field; }
set
{
if (_field != value)
{
_field = value;
OnPropertyChanged("Field");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
i am using radgridview in usercontrol and its not binding at all please advice
<UserControl xmlns:Views="clr-namespace:ClientModule.Views" >
<Views:InfoGridView />
</UserControl>
<UserControl x:Class="ClientModule.Views.InfoGridView">
<Controls:RadGridView x:Name="radGridViewOverview" IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Binding RepaymentInfo, Mode=TwoWay, Path=RepaymentInfo, ElementName=PosSearchView}" >
</UserControl>
Can you verify what will happen if you change the grid temporary to a simple ListBox with the same binding?
Kind regards,Vlad
the Telerik team
Hello Tim, I have a viewmodel with an ObservableCollection<X> where X does implement INotifyPropertyChanged and so does my ViewModel and yet when I bind it to a RadGridView I do not get updates when any property within X changes neither if I add/delete rows in the UI on the collection itself.
I am a bit flummoxed, so would appreciate if you can help me resolve this issue.
I have tested the approach explained in the last post using the latest version of our controls and wasn't able to reproduce it on my side. I attached to this reply the project which I used to test this scenario. Can you give it a try and let me know if I missing something. You can modify the project to reproduce this behavior and set it back.
Regards,
Dinko
Progress Telerik