Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4345222
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:00:22+00:00 2026-05-21T12:00:22+00:00

I have a DataGrid where one column needs to be aligned to the right.

  • 0

I have a DataGrid where one column needs to be aligned to the right. To do this I use

<DataGridTextColumn.CellStyle>
  <Style>
    <Setter Property="FrameworkElement.HorizontalAlignment" Value="Right"/>
  </Style>
</DataGridTextColumn.CellStyle>

which works fine as shown here:

enter image description here

Unfortunately the aligned cells are not properly highlighted when a row is selected. Only the data is highlighted, but the empty area to the left of the data is not, as shown here:

enter image description here

Additionally, the area to the left of the data is not sensitive to mouse-clicks anymore. In the example above, a click to the left of ‘12.34’ will not select the first row (but a click to the right of ‘A1’ will). Altogether this makes for a bad user experience.

So, how do I do HorizontalAlignment without breaking row-selection? I want the entire row highlighted, and I want to be able to click anywhere to select a row.

I am using VS 2010, .NET 4, both Win XP and Win 7.

The code to reproduce my example:

namespace WpfApplication2
{
  public class ListItem
  {
    public string FieldA { get; set; }
    public decimal FieldB { get; set; }
    public string FieldC { get; set; }
  }
}

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:My="clr-namespace:WpfApplication2" 
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <x:Array x:Key="List" Type="{x:Type My:ListItem}">
            <My:ListItem FieldA="A1" FieldB="12.34" FieldC="C1"/>
            <My:ListItem FieldA="A2" FieldB="1000.00" FieldC="C2"/>
            <My:ListItem FieldA="A3" FieldB="987.6" FieldC="C3"/>
        </x:Array>
    </Window.Resources>
    <Grid>
        <DataGrid ItemsSource="{StaticResource List}" AutoGenerateColumns="False" SelectionUnit="FullRow" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="ColumnA" Binding="{Binding Path=FieldA}" Width="150" />
                <DataGridTextColumn Header="ColumnB" Binding="{Binding Path=FieldB, StringFormat='#,##0.00'}" Width="150" >
                    <DataGridTextColumn.CellStyle>
                        <Style>
                            <Setter Property="FrameworkElement.HorizontalAlignment" Value="Right"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                <DataGridTextColumn Header="ColumnC" Binding="{Binding Path=FieldC}" Width="*" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:00:22+00:00Added an answer on May 21, 2026 at 12:00 pm

    Try DataGridTextColumn.ElementStyle and (if needed) DataGridTextColumn.EditingElementStyle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid in Flex, with one column a checkbox and another a
I have a DataGrid, populated with objects in an ArrayCollection. After updating one of
I have a DataGrid where each column has a SortExpression. I would like the
I have a DataGrid that needs to show a gradient background on mouseover of
I have a datagrid. A column of the datagrid is a simple <DataGridTemplateColumn> with
I have a DataGrid (the official one) with SelectionUnit=Cell . When the user selects
I have a WPF4 DataGrid (the one that's included with WPF4) with columns 'Surname',
I have a Silverlight 4 application that uses a DataGrid. This DataGrid is bound
I have a datagrid getting bound to a dataset, and I want to display
I have a datagrid, populated as shown below. When the user clicks on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.