Hi,
I am using the ObservableCollection as the datasource for the grid.
In a button click i open another window and changing the data. and sending the message to the main window to refresh the grid.
but, setting the data source to null and setting the source again is not refreshing.
How can i refresh the grid to get the updated data?
this example works fine, because the NotifyPropertyChanged is called with a non empty string.
But we use in our abstract classes the event with an empty string, because we don't know the exact change of an specific property (we generate the classes dynamicly at start up). An empty string is allowed with a NotifyPropertyChangedevent.
When I use our Collection in the Xceed DataGrid all works fine!
best regards
Hello,
I have created a sample application with a XamDataGrid binding to an Observable Collection. I have added 5 items in it. By changing the values of the grid through the UI changes the value in the collection and it works fine. Here is the xaml and code-behind code of my sample:
<Grid> <igDP:XamDataGrid Margin="2,8,2,90" Name="xamDataGrid1" /> <Button Height="32" HorizontalAlignment="Left" Margin="180,0,0,28" Name="button1" VerticalAlignment="Bottom" Width="94" Click="button1_Click">Button</Button> </Grid>
ObservableCollection<DemoCustomer> customers; public Window1() { InitializeComponent(); customers = new ObservableCollection<DemoCustomer>(); customers.Add( new DemoCustomer("Alex","2222222")); customers.Add(new DemoCustomer("Peter", "2352222")); customers.Add(new DemoCustomer("George", "22423222")); customers.Add(new DemoCustomer("Dimitri", "228672222")); customers.Add(new DemoCustomer("John", "222675622")); xamDataGrid1.DataSource = customers; } #region Customer Class public class DemoCustomer : INotifyPropertyChanged { private Guid idValue = Guid.NewGuid(); private string customerNameValue = String.Empty; private string phoneNumberValue = String.Empty; public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } public DemoCustomer(string name, string number) { this.CustomerName = name; this.PhoneNumber = number; } public static DemoCustomer CreateNewCustomer() { return new DemoCustomer(); } public Guid ID { get { return this.idValue; } } public string CustomerName { get { return this.customerNameValue; } set { if (value != this.customerNameValue) { this.customerNameValue = value; NotifyPropertyChanged("CustomerName"); } } } public string PhoneNumber { get { return this.phoneNumberValue; } set { if (value != this.phoneNumberValue) { this.phoneNumberValue = value; NotifyPropertyChanged("PhoneNumber"); } } } } #endregion
Or if this is not the solution I am missing something?
What is if the custom classes implement the INotifyPropertyChanged ?
I think that the xamDataGrid has a bug, if it use a ObserveableCollection !!! The values in cells are not updated!!!
That doesn't sound right to me.
The fact that it's an ObserveableCollection will inherently caseu the grid to update for CHANGED items, NEW items and REMOVED items. You won't need to refresh the list for CHANGED data. Of course, this all depends on what your definition of changing the data is.
if you need to change out the entire collection and need the grid to refresh, you do as you mentioned, setting the DataSource -> null and then back to the new collection.
One thought: what are the objects in the collection? Are they custom Classes? If so, you need to implement INotifyPropertyChanged so that the grid can see these individual property changes.