[英]DataGridCellEditEnding event is not firing when I am changing dropdown inside my datagrid in WPF
I am using the following code to use a ComboBox
inside my DataGridTemplateColumn
: 我正在使用以下代码在DataGridTemplateColumn
使用ComboBox
:
<DataGridTemplateColumn Header="MyHeader" Width="50">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Width="Auto" Text="{Binding Path=MyVal}" ToolTip="{Binding MyDisplayName}"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Width="50" Height="17" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Path=DataContext.MyList}"
SelectedValuePath="MyValPath" SelectedValue="{Binding MySelectedVal}" SelectedItem="{Binding MyObject}" DisplayMemberPath="MyDisplayName"
FontSize="12" >
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
CellTemplate
is for showing my text (custom text for selected value) and CellEditingTemplate
contains my ComboBox
which has the actual list. CellTemplate
用于显示我的文本(用于选定值的自定义文本),而CellEditingTemplate
包含我的ComboBox
,其中包含实际列表。
When I select a value from my drop-down, I have to click on another part of the data grid to get DataGridDiagnosticCellEditEnding
fired. 当从下拉列表中选择一个值时,我必须单击数据网格的另一部分以激发DataGridDiagnosticCellEditEnding
。
I want to get it fired as soon as I select a value or change a value from my ComboBox
. 我想在选择值或从ComboBox
更改值后立即将其触发。
I tried adding the following code, but it didn't work: 我尝试添加以下代码,但是没有用:
<ComboBox Width="50" Height="17" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}},Path=DataContext.MyList}"
SelectedValuePath="MyValPath" SelectedValue="{Binding MySelectedVal}" SelectedItem="{Binding MyObject, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="MyDisplayName" FontSize="12" >
Also I tried adding IsSynchronizedWithCurrentItem="True"
. 我也尝试添加IsSynchronizedWithCurrentItem="True"
。
I gave a try to your code, and ve got a fix : 我尝试了您的代码,并已解决:
On the ComboBox of the DataGrid Column, subscribe to the closing event 在“ DataGrid列”的ComboBox上,订阅关闭事件
Implement the event Handler and raise a routed Event. 实现事件处理程序并引发路由事件。
CommitEditCommand belongs to the DataGrid class : CommitEditCommand属于DataGrid类:
private void ComboBoxDropDownClosed(object sender, EventArgs e)
{
DataGrid.CommitEditCommand.Execute(datagrid1,datagrid1);
}
From there you fall in the DataGrid.CellEditting breakpoint 从那里您落入DataGrid.CellEditting断点
Here is the working solution : http://1drv.ms/1LFB5Gc 这是有效的解决方案: http : //1drv.ms/1LFB5Gc
Regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.