Click here to Skip to main content
13,096,268 members (54,032 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How i can set the background color of a selected cell ie when a cell gets focus it should be able set the background color programmatically.

2. How I Can align the text in TextBoxcolumn(cells)in a DataGrid to left center or right programmatically

3. How I can select a cell by single mouse click

Best regards


Thanks in advance
Posted 13-Jan-12 4:01am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hope this helps:
<DataGrid AutoGenerateColumns="False"
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                      Color="Red" />
    <DataGridTextColumn Header="Nombre"
                        Binding="{Binding Nombre}">
    <Style TargetType="DataGridColumnHeader">
      <Setter Property="HorizontalContentAlignment"
              Value="Center" />
        <Style TargetType="TextBlock">
          <Setter Property="TextAlignment"
                  Value="Right" />
    <DataGridTextColumn Header="Apellido"
                        Binding="{Binding Apellido}">

Now includes header Alignment :o)
MohammadIqbal 13-Jan-12 11:59am
Thanks Nestor it worked fine. but for header alignment what shall I do

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 13 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100