如何覆盖/隐藏 DataRow 上的 SetModified 方法?
我正在尝试对 DataRow
对象的 RowState
属性实现更改通知。
这是我到目前为止所拥有的,但我的 SetModified
方法从未被调用:
internal class DataRowEx : DataRow, INotifyPropertyChanged
{
#region Events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Construction
public DataRowEx(DataRowBuilder builder)
: base(builder)
{ }
#endregion
#region Overrides
protected new void SetModified()
{
base.SetModified();
PropertyChanged(this, new PropertyChangedEventArgs("RowState"));
}
#endregion
}
我想我可以将其设置为内部并从包含该行的对象中自己调用它,但我觉得应该有更好的方法。
I'm trying to implement change notification on the RowState
property of a DataRow
object.
Here's what I have so far, but my SetModified
method never gets called:
internal class DataRowEx : DataRow, INotifyPropertyChanged
{
#region Events
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Construction
public DataRowEx(DataRowBuilder builder)
: base(builder)
{ }
#endregion
#region Overrides
protected new void SetModified()
{
base.SetModified();
PropertyChanged(this, new PropertyChangedEventArgs("RowState"));
}
#endregion
}
I suppose I could make it internal and call it myself from the object containing the row, but I feel like there should be a better way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataTable
与DataRow
配合使用,因此永远不会调用DataRowEx
中的SetModified()
(它“隐藏”继承的成员,它不会覆盖它)。实现您想要的效果的最简单方法可能是还实现自定义
DataTable
,重写OnRowChanging()
或OnRowChanged()
,然后委托从那里到DataRowEx
中的自定义功能。The
DataTable
works withDataRow
and, as such, will never call yourSetModified()
inDataRowEx
(it "hides" the inherited member, it doesn't override it).Probably the easiest way of achieving what you want is to also implement a custom
DataTable
, override eitherOnRowChanging()
orOnRowChanged()
, and delegate to custom functionality in yourDataRowEx
from there.