此示例展示了如何突出用户所编辑的网格单元格。当用修改一个值,然后离开所修改的单元格时,单元格背景会变红。
C#
<Window x:Class="HighlightModifiedCells.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" Title="How to change background color for modified cells" Height="500" Width="400">
<Window.Resources>
<Style x:Key="CellStyle" TargetType="{x:Type dxg:CellContentPresenter}">
<Setter Property="Margin" Value="1,3,1,3" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="MinHeight" Value="19" />
</Style>
</Window.Resources>
<DockPanel>
<Button DockPanel.Dock="Top" Click="Button_Click">Reset</Button>
<dxg:GridControl x:Name="grid" CustomUnboundColumnData="grid_CustomUnboundColumnData">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Number1" />
<dxg:GridColumn FieldName="Number2" />
<dxg:GridColumn FieldName="Text1" />
<dxg:GridColumn FieldName="Text2" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" CellValueChanged="view_CellValueChanged" />
</dxg:GridControl.View>
</dxg:GridControl>
</DockPanel>
</Window>
NB.NET
<Window x:Class="HighlightModifiedCells.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" Title="How to change background color for modified cells" Height="500" Width="400">
<Window.Resources>
<Style x:Key="CellStyle" TargetType="{x:Type dxg:CellContentPresenter}">
<Setter Property="Margin" Value="1,3,1,3" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="MinHeight" Value="19" />
</Style>
</Window.Resources>
<DockPanel>
<Button DockPanel.Dock="Top" Click="Button_Click">Reset</Button>
<dxg:GridControl x:Name="grid" CustomUnboundColumnData="grid_CustomUnboundColumnData">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Number1" />
<dxg:GridColumn FieldName="Number2" />
<dxg:GridColumn FieldName="Text1" />
<dxg:GridColumn FieldName="Text2" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" CellValueChanged="view_CellValueChanged" />
</dxg:GridControl.View>
</dxg:GridControl>
</DockPanel>
</Window>
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [https://www.devexpresscn.com/]
本文地址:https://www.devexpresscn.com/post/322.html