0

In my program I have a DataGrid with 4 different columns. I would like to make it so that, in one of the columns, when a cell is selected for editing, I am able to change the content of that cell programmatically. For example, on edit, the current string value in the selected cell might change to "selected". I've looked through the DataGridCell class here, and haven't really found anything that would detect an edit to a cell. It would be nice if there was like some "cellClick" event for each DataGridTextColumn in xaml. How do I achieve this type of handler?

The xaml of my DataGrid:

<DataGrid ItemsSource="{Binding SysModel.SystemCollection}" MinColumnWidth="50" ColumnHeaderStyle="{StaticResource HeaderStyle}" RowStyle="{StaticResource RowStyleWithAlternation}" CellStyle="{StaticResource CenterCellStyle}"
          RowHeaderWidth="0" AlternationCount="2" GridLinesVisibility="Horizontal" SelectionUnit="Cell" CanUserAddRows="False" AutoGenerateColumns="False" Height="471" Name="dataGrid1" Width="468" Canvas.Left="40" Canvas.Top="17">
    <DataGrid.Columns>
        <DataGridTextColumn Header="{DynamicResource cart}" Width="Auto" IsReadOnly="True" Binding="{Binding cartNum}" />
        <DataGridTextColumn Header="{DynamicResource ipAddress}" Width="100" IsReadOnly="False" Binding="{Binding ipAddress}" />
        <DataGridTextColumn Header="{DynamicResource portNumber}" Width="70" IsReadOnly="False" Binding="{Binding PortNumber}" />
        <!-- **This is the column that contains the cells I want to have this event for** -->
        <DataGridTextColumn Header="{DynamicResource configuration}" Width="*" IsReadOnly="False" Binding="{Binding Configuration}" />
        </DataGrid.Columns>
        <DataGrid.Resources>
            <SolidColorBrush Color="#726AA5" x:Key="{x:Static SystemColors.HighlightBrushKey}" />
        </DataGrid.Resources>
</DataGrid>
4

1 に答える 1

0

DataGridCell選択Selectedされたときにイベントを発生させます。ユーザーが編集する前に、選択する必要があると思います。

ソース: DataGridCell イベント

于 2014-12-18T19:53:30.513 に答える