We are using a DataRow object that implements DynamicObject and INotifyPropertyChanged to bind data to Grid. Using the latest builds (I have tried up to the 5/27 hotfix) if we add a new column or change the value of one of the DataRow fields at runtime, which triggers a PropertyChangedEventHandler to fire, the grid is not reflecting the value change. I don't even see a call being made to DataRow to get retrieve the new value.
If I revert to the last version we were using (2012 Q3), with no code changes, the functionality works again. Is this a known issue? Is there a fix for this?
public class DataRow : DynamicObject, INotifyPropertyChanged
{
private IDictionary<string, object> columns;
public DataRow()
{
columns = new Dictionary<string, object>();
}
public DataRow(IDictionary<string, object> source)
{
columns = source;
}
public override IEnumerable<string> GetDynamicMemberNames()
{
return columns.Keys;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = this[binder.Name];
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
this[binder.Name] = value;
return true;
}
public void RemoveColumn(string columnName)
{
columns.Remove(columnName);
}
public object this[string columnName]
{
get
{
if (columns.ContainsKey(columnName))
{
return columns[columnName];
}
return null;
}
set
{
if (!columns.ContainsKey(columnName))
{
columns.Add(columnName, value);
OnPropertyChanged(columnName);
}
else
{
if (columns[columnName] != value)
{
columns[columnName] = value;
OnPropertyChanged(columnName);
}
}
}
}
public DataRow Clone()
{
return new DataRow(new Dictionary<string, object>(this.columns));
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
If I revert to the last version we were using (2012 Q3), with no code changes, the functionality works again. Is this a known issue? Is there a fix for this?
public class DataRow : DynamicObject, INotifyPropertyChanged
{
private IDictionary<string, object> columns;
public DataRow()
{
columns = new Dictionary<string, object>();
}
public DataRow(IDictionary<string, object> source)
{
columns = source;
}
public override IEnumerable<string> GetDynamicMemberNames()
{
return columns.Keys;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = this[binder.Name];
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
this[binder.Name] = value;
return true;
}
public void RemoveColumn(string columnName)
{
columns.Remove(columnName);
}
public object this[string columnName]
{
get
{
if (columns.ContainsKey(columnName))
{
return columns[columnName];
}
return null;
}
set
{
if (!columns.ContainsKey(columnName))
{
columns.Add(columnName, value);
OnPropertyChanged(columnName);
}
else
{
if (columns[columnName] != value)
{
columns[columnName] = value;
OnPropertyChanged(columnName);
}
}
}
}
public DataRow Clone()
{
return new DataRow(new Dictionary<string, object>(this.columns));
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}