I know that I can pragmatically add selected items by either of the following:
xamDataGrid1.Records[0].IsSelected = true;
xamDataGrid1.SelectedItems.Records.Add(xamDataGrid1.Records[1]);
However the records in the grid do not get highlighted. How do I make the selected items appear highlighted in the grid?
Hello Chris,
If you want to use the ‘CellValuePresenter’ style in your scenario you need to set the following data trigger like e.g. :
<Style TargetType="igDPx:CellValuePresenter">
<Style.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#7FF6FBFD"/>
<GradientStop Offset="0.99" Color="#7FD5EFFC"/>
<GradientStop Color="#7Fffffff" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
<Setter Property="Background" Value="{Binding Path=Record.Index, RelativeSource={RelativeSource Self}, Converter={StaticResource BackgroundConverter}}"/>
</Style>
Let me know, if you need any further assistance.
Yanko,
The only issue I run into now is that when I am using horizontal orientation, I want to alternate each field background color instead of each record. To do this I use a CellValuePresenterStyle which causes the selected records to not appear highlighted.
In vertical orientation I am alternating each record background using the DataRecordCellArea style and the selected records become highlighted correctly.
Is there a way to alternate each field background color and still have the selected records highlighted correctly?
Thanks,
Chris
Hi Chris,
Thank you for the provided sample application. I have been looking into it and I can suggest you define the style for the ‘DataRecordCellArea’ instead of ‘CellValuePresenter’.
This way the selected records will be highlighted.
Let me know if you need any further assistance on this matter.
Here is a sample that I made. When I use the cell value presenter style the records don't become highlighted when I select them.
Let me know if you have a solution for this.
Hello,
Thank you for your post. I have activated the highlighting of the alternate records and the selected records highlight when I select them through code.
I am attaching a modified version of my sample application(DataGridSelectedRecordsModified.zip).
If you need any further assistance on this matter, it will be great to modify the sample application as this way I will see what exactly is your scenario.
Looking forward to hearing from you.