WPF DataGrid有rowedi照管,但没有rowedi照管。

时间:2022-07-06 09:05:47

I've bound an ObservableCollection to a DataGrid. When I change values in the DataGrid, the RowEditEnding event is raised. But the e.Row.Item is the object before editing, so you don't see the new values. I understand that because of the EditEnding. In Silverlight you have an EditEnded event, how can I get the object with the new values when I edit the DataGrid.

我已将一个天文台连接到一个数据网格上。当我在DataGrid中更改值时,将引发roweditend事件。但e.Row。项目是编辑之前的对象,所以您不会看到新的值。我理解这一点是因为我的编辑。在Silverlight中有一个编辑事件,如何在编辑DataGrid时获得具有新值的对象。

thanks,

谢谢,

Filip

菲利普

5 个解决方案

#1


8  

From http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c38fc695-d1ec-4252-87b7-feb484ee01e4/, change the UpdateSourceTrigger of the Binding to PropertyChanged. The Property will then be updated immediately, before the RowEditEnding event, and the new value can be accessed from the RowEditEnding event handler.

从http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c38fc695-d1ec-4252-87b7-feb484ee01e4/,将绑定的updatesource触发器更改为PropertyChanged。然后,该属性将在roweditend事件之前立即更新,并且可以从roweditend事件处理程序访问新值。

For example, for a DataGridComboBoxColumn

例如,对于DataGridComboBoxColumn

SelectedItemBinding="{Binding ForTestResult, UpdateSourceTrigger=PropertyChanged}"

This seems a very simple way to solve this issue.

这似乎是解决这个问题的一个非常简单的方法。

In addition, although I have not tried it, I think it should be easy to also access the original value before editing if your object implements IEditableObject.

此外,虽然我还没有尝试过,但是我认为如果您的对象实现了IEditableObject,那么在编辑之前也应该很容易地访问原始值。

#2


6  

Well, maybe this may help: http://wpf.codeplex.com/Thread/View.aspx?ThreadId=39356

好吧,也许这能帮上忙:http://wpf.codeplex.com/thread/view.aspx?

http://blogs.msdn.com/b/vinsibal/archive/2009/04/14/5-more-random-gotchas-with-the-wpf-datagrid.aspx

http://blogs.msdn.com/b/vinsibal/archive/2009/04/14/5-more-random-gotchas-with-the-wpf-datagrid.aspx

Or this, see point number 5.

或者这个,见点5。

You'll have to tinker with it to get what you want I think, but I hope that helps! Or points you in a good direction.

我想,你得修改一下才能得到你想要的,但我希望这能有所帮助!或者给你指出一个好的方向。

#3


1  

This solution seems simple enough. Referred from msdn forum.

这个解决方案似乎很简单。被称为从msdn论坛。

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);
}

#4


0  

Attach to the ObservableCollection's changed event.

连接到观测记录的变化事件。

I bound to a DataTable and used the RowChanged event.

我绑定到一个DataTable,并使用RowChanged事件。

#5


0  

My fresh and IMHO fastest way is to add bool rowEdited=false, then set it to true inside DataGrid_RowEditEnding and put your code for 'editEnded' inside DataGrid_LayoutUpdated:

我最新最快的方法是添加bool rowEdited=false,然后在datagrid_rowediting中将其设置为true,并在DataGrid_LayoutUpdated中添加“editend”代码:

if (rowEdited)
{
    //main code here//
    rowEdited=false;
}

.

#1


8  

From http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c38fc695-d1ec-4252-87b7-feb484ee01e4/, change the UpdateSourceTrigger of the Binding to PropertyChanged. The Property will then be updated immediately, before the RowEditEnding event, and the new value can be accessed from the RowEditEnding event handler.

从http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c38fc695-d1ec-4252-87b7-feb484ee01e4/,将绑定的updatesource触发器更改为PropertyChanged。然后,该属性将在roweditend事件之前立即更新,并且可以从roweditend事件处理程序访问新值。

For example, for a DataGridComboBoxColumn

例如,对于DataGridComboBoxColumn

SelectedItemBinding="{Binding ForTestResult, UpdateSourceTrigger=PropertyChanged}"

This seems a very simple way to solve this issue.

这似乎是解决这个问题的一个非常简单的方法。

In addition, although I have not tried it, I think it should be easy to also access the original value before editing if your object implements IEditableObject.

此外,虽然我还没有尝试过,但是我认为如果您的对象实现了IEditableObject,那么在编辑之前也应该很容易地访问原始值。

#2


6  

Well, maybe this may help: http://wpf.codeplex.com/Thread/View.aspx?ThreadId=39356

好吧,也许这能帮上忙:http://wpf.codeplex.com/thread/view.aspx?

http://blogs.msdn.com/b/vinsibal/archive/2009/04/14/5-more-random-gotchas-with-the-wpf-datagrid.aspx

http://blogs.msdn.com/b/vinsibal/archive/2009/04/14/5-more-random-gotchas-with-the-wpf-datagrid.aspx

Or this, see point number 5.

或者这个,见点5。

You'll have to tinker with it to get what you want I think, but I hope that helps! Or points you in a good direction.

我想,你得修改一下才能得到你想要的,但我希望这能有所帮助!或者给你指出一个好的方向。

#3


1  

This solution seems simple enough. Referred from msdn forum.

这个解决方案似乎很简单。被称为从msdn论坛。

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);
}

#4


0  

Attach to the ObservableCollection's changed event.

连接到观测记录的变化事件。

I bound to a DataTable and used the RowChanged event.

我绑定到一个DataTable,并使用RowChanged事件。

#5


0  

My fresh and IMHO fastest way is to add bool rowEdited=false, then set it to true inside DataGrid_RowEditEnding and put your code for 'editEnded' inside DataGrid_LayoutUpdated:

我最新最快的方法是添加bool rowEdited=false,然后在datagrid_rowediting中将其设置为true,并在DataGrid_LayoutUpdated中添加“editend”代码:

if (rowEdited)
{
    //main code here//
    rowEdited=false;
}

.