---
title: "WPF overrided datagrid how to set DatagridCell Selected style"  
description: "WPF overrided datagrid how to set DatagridCell Selected style"  
author: "E E Cummings"  
published: 2013-07-19  
updated: 2013-07-19  
canonical: https://www.mindstick.com/forum/1341/wpf-overrided-datagrid-how-to-set-datagridcell-selected-style  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# WPF overrided datagrid how to set DatagridCell Selected style

I have overrides DataGrid. Below are my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) and XAML. How can I set [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) to change the DataGridCell [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) colour when the cell is selected?

<vw:DataGridExt

Grid.Row="1"

AlternatingRowBackground="LightGray"

ItemsSource="{[Binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) RelativeSource={RelativeSource TemplatedParent},[Path](https://www.mindstick.com/articles/44333/4-expert-tips-on-how-to-pick-the-right-career-path)=[Value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages),Mode=OneWay, IsAsync=[True](https://yourviews.mindstick.com/view/81326/boycott-chinese-products-dream-will-come-true)}"

Background="White"

AutoGenerateColumns="True"

IsReadOnly="True"

CanUserResizeRows="False"

ClipboardCopyMode="IncludeHeader"

CanUserSortColumns="True"

CanUserAddRows="False"

SelectionMode="Extended"/>

[public](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) DataGridExt : DataGrid

{

public DataGridExt()

{

this.AutoGeneratedColumns += new EventHandler(DataGrid_AutoGeneratedColumns);

}

}

thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by shreesh chandra shukla

Solution!

You have to provide a style for your DataGridCell

```
<Style TargetType="{x:Type
DataGridCell}">     <Setter Property="Background" Value="Transparent" />            <Setter Property="BorderThickness" Value="1"/>    <Setter Property="BorderBrush" Value="Transparent"/>         <Setter Property="Template">       
<Setter.Value>           
<ControlTemplate TargetType="{x:Type DataGridCell}">               
<Border Background="{TemplateBinding Background}"                        
BorderBrush="{TemplateBinding BorderBrush}"                          BorderThickness="{TemplateBinding
BorderThickness}" >                   
<ContentPresenter />               
</Border>                                         
</ControlTemplate>       
</Setter.Value>    </Setter>    <Style.Triggers>        <Trigger Property="IsKeyboardFocusWithin" Value="True">            <Setter Property="BorderBrush" Value="Black" />       
</Trigger>        <Trigger Property="IsSelected" Value="True">            <Setter Property="Background" Value="Gray"/>       
</Trigger>   
</Style.Triggers></Style>
```

and set

SelectionUnit="Cell" for your DataGrid.


---

Original Source: https://www.mindstick.com/forum/1341/wpf-overrided-datagrid-how-to-set-datagridcell-selected-style

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
