我是 WPF 的新手,几天来我找不到我的问题的答案。请指出我有用的链接...
我有一个绑定到数据网格的数据表。
public class Customers:INotifyPropertyChanged
private DataTable _contacts;
public DataTable Contacts
{
get { return _contacts; }
set
{
_contacts = value;
OnPropertyChanged("Contacts");
}
}
public Customers()
{
RaisePropertyChanged("Contacts");
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
if(string.Compare(propertyName,"Contacts")==0)
{
var CustomerContacts = new CustomerContactsTable();
if (Id != null)
CustomerContacts.GetTableByCustomerId(Id);
Contacts = CustomerContacts;
//..here is logic for other properties..
}
}
这是xaml:
<DataGrid ItemsSource="{Binding Path=Contacts}" TargetUpdated="dgContacts_TargetUpdated">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name,NotifyOnTargetUpdated=True}" ClipboardContentBinding="{x:Null}" />
<DataGridTextColumn Binding="{Binding TelNo,NotifyOnTargetUpdated=True}" ClipboardContentBinding="{x:Null}" />
</DataGrid.Columns>
</DataGrid>
我不知道如何更好地将数据更新到数据库中。我想获得两个指定数据行的列表:包含更新行的列表(在里面的新行内)和包含已删除行的列表。我想处理整行,而不是单元格。而且我不使用 DataTableAdapter。datagrid 中的任何更改现在都不提供 sourcecollection 的更新。使用什么事件会更好(OnTargetUpdated、RowEditEnding 等)?请不要打我这么多。提前致谢!