如何使DataGrid在编辑后立即保存单元格中的更改

时间:2016-07-20 10:56:10

标签: c# wpf datagrid

是否有更简单的内容(How to make GridControl immediately save changes in a cell after editing)允许在选择时更新DataGrid而无需点击其他地方?

更新数据的代码不存在问题,但是在编程选择后如何离开单元格。

在进行选择之前使用SelectionChanged事件触发。

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
             //Code here
        }

我目前正在使用CellEditEnding

private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        { 
            // code
        }

XAML用于数据绑定,

    <DataGrid Name="MainTable" VerticalAlignment="Stretch"
        AutoGenerateColumns="False" ItemsSource="{Binding .}" 
        Margin="5" Grid.Row="2" Grid.RowSpan="2"
        Grid.ColumnSpan="4" AlternationCount="2" CanUserAddRows="True"
        GridLinesVisibility="None" 
        CellEditEnding="DataGrid_CellEditEnding" >
                   <DataGrid.Columns>                          
                            <DataGridTemplateColumn Header="Info" Width="*" SortMemberPath="Words">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock FontWeight="Light" Text="{Binding Path=Info_Data, UpdateSourceTrigger=PropertyChanged}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>

                                <DataGridTemplateColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <ComboBox FontWeight="Light" Loaded="ComboBox_Loaded" Text="{Binding Path=Info_Data, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding InfoCollection, Source={StaticResource InfoDataComboBox}}">
                                        </ComboBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellEditingTemplate>
                            </DataGridTemplateColumn>
                   </DataGrid.Columns>

有什么想法吗?

0 个答案:

没有答案