[英]WPF DataGrid CanUserAddRows event
有沒有可以使用的事件或命令,以便可以在添加對象之前調用要添加到ObservableCollection的對象?
此刻,一旦用戶單擊網格中的行,它將把它添加到集合中,但是我需要在C#中專門分配我不想在網格中分配的屬性。
public void event
{
// I want to do something before the CanUserAddRow event does this
collection.Add(<T>;
}
您可以使用DataGrid.InitializingNewItem
事件:
private void InitializingNewItem(object sender, InitializingNewItemEventArgs e)
{
//use e.NewItem here
}
從MSDN
您可以通過處理InitializingNewItem事件並以編程方式設置值來設置新項目的默認值
我不確定這是否適合您...
private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
YourObject obj = e.Row.Item as YourObject;
if (obj != null)
{
//see obj properties
}
}
說明:
用戶在此處將數據輸入到網格后,它將作為e.Row.Item
然后,您可以更改對對象的任何修改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.