locked
WPF DataGrid Row Select Color RRS feed

  • Question

  • Hello,

    when i click a row, the row is selected with a blue background.Is there a way to hide the selection ?

    Thanks !

    Tuesday, January 18, 2011 9:18 PM

Answers

  • Hi,

     <DataGrid SelectionMode="Single" FrozenColumnCount="1" AutoGenerateColumns="True" Height="240" HorizontalAlignment="Left" Margin="30,35,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="447">
                <DataGrid.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Yellow">
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.CellStyle>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Yellow">
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.RowStyle>
            </DataGrid>

    this is a simple code to change the row selection color,

    please customize at your need.

    if you have white row color please replace yellow with white.

    one more thing you need to set foregroundcolor also.

    Best of luck


    Md. Masudur Rahman
    • Proposed as answer by Jie Bao Wednesday, January 19, 2011 9:29 AM
    • Marked as answer by Jie Bao Thursday, January 27, 2011 3:51 AM
    Wednesday, January 19, 2011 7:57 AM

All replies

  • Hi,

     <DataGrid SelectionMode="Single" FrozenColumnCount="1" AutoGenerateColumns="True" Height="240" HorizontalAlignment="Left" Margin="30,35,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="447">
                <DataGrid.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Yellow">
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.CellStyle>
                <DataGrid.RowStyle>
                    <Style TargetType="DataGridRow">
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Yellow">
                                </Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </DataGrid.RowStyle>
            </DataGrid>

    this is a simple code to change the row selection color,

    please customize at your need.

    if you have white row color please replace yellow with white.

    one more thing you need to set foregroundcolor also.

    Best of luck


    Md. Masudur Rahman
    • Proposed as answer by Jie Bao Wednesday, January 19, 2011 9:29 AM
    • Marked as answer by Jie Bao Thursday, January 27, 2011 3:51 AM
    Wednesday, January 19, 2011 7:57 AM
  • Hi Rajeshvee,

    Same with your other thread: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b967e635-7e76-4c80-a16a-042aa6350030

    We could modify the style for the DataGridRow, and change the color or remove the triggers from the Style.

    So Masudur's solution can work.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jie Bao Thursday, January 27, 2011 3:51 AM
    • Unmarked as answer by Jie Bao Thursday, January 27, 2011 3:51 AM
    Wednesday, January 19, 2011 9:32 AM