我已經將一個ObservableCollection綁定到DataGrid。當我更改DataGrid中的值時,會引發RowEditEnding事件。但e.Row.Item是編輯前的對象,所以你看不到新的值。我明白,因爲EditEnding。在Silverlight中,您有一個EditEnded事件,在編輯DataGrid時如何獲得具有新值的對象。WPF DataGrid有RowEditEnding但沒有RowEditEnded
感謝,
菲利普
我已經將一個ObservableCollection綁定到DataGrid。當我更改DataGrid中的值時,會引發RowEditEnding事件。但e.Row.Item是編輯前的對象,所以你看不到新的值。我明白,因爲EditEnding。在Silverlight中,您有一個EditEnded事件,在編輯DataGrid時如何獲得具有新值的對象。WPF DataGrid有RowEditEnding但沒有RowEditEnded
感謝,
菲利普
好吧,也許這可以幫助:http://wpf.codeplex.com/Thread/View.aspx?ThreadId=39356
http://blogs.msdn.com/b/vinsibal/archive/2009/04/14/5-more-random-gotchas-with-the-wpf-datagrid.aspx
還是這個,見點5號
你得鼓搗用它來得到我想要的東西,但我希望這有助於!或者指出你的方向很好。
附加到ObservableCollection的已更改事件。
我綁定到一個DataTable並使用RowChanged事件。
更改集合中某個項目的一個屬性時不起作用。 – 2013-01-23 08:49:28
從http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c38fc695-d1ec-4252-87b7-feb484ee01e4/,將Binding的UpdateSourceTrigger更改爲PropertyChanged。該屬性將在RowEditEnding事件之前立即更新,並且可以從RowEditEnding事件處理程序訪問新值。
例如,對於一個DataGridComboBoxColumn
SelectedItemBinding="{Binding ForTestResult, UpdateSourceTrigger=PropertyChanged}"
這似乎是個很簡單的方法來解決這個問題。另外,儘管我還沒有嘗試過,但我認爲如果你的對象實現了IEditableObject,在編輯之前也應該很容易地訪問原始值。
謝謝,這應該是答案! – orangesherbert 2013-01-06 16:46:25
不適用于格式化值日期,小數等僅適用於字符串。 – 2013-01-23 08:43:30
我也認爲這應該是答案,所以我upvoted – 2016-06-20 11:32:02
這個解決方案看起來很簡單。來自msdn forum。
private void dgEmployees_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
Action action = delegate
{
Employee emp = e.Row.Item as Employee;
//do something nice to the employee
};
Dispatcher.BeginInvoke(action, System.Windows.Threading.DispatcherPriority.Background);
}
我的新鮮和恕我直言,最快的方式是添加bool rowEdited=false
,然後將其設置爲true
內DataGrid_RowEditEnding
,把你的代碼裏面DataGrid_LayoutUpdated
'editEnded':
if (rowEdited)
{
//main code here//
rowEdited=false;
}
。
難以置信MS還沒有實現這樣的基本事件。第一次在Silverlight中比在WPF中更容易。 :)第二個鏈接點5是答案!爲我工作。很多謝謝 – Houman 2011-07-21 14:45:16