This is a migrated thread and some comments may be shown as answers.

Column TextAlignment isn't working

10 Answers 335 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
danparker276
Top achievements
Rank 2
danparker276 asked on 31 Aug 2011, 10:25 PM
Everything just aligns to the left.

                    <telerik:GridViewDataColumn  Header="Date" DataMemberBinding="{Binding EntDate, Converter={StaticResource NQtoDateTime}}" DataFormatString="{}{0:d}" TextAlignment="Right">

I saw someone had a similar problem, and closed their IDE and it worked.  I'm using XP.  HeaderTextAlignment, or TextAlignment doesn't work on all of my girds now.  I know they used to work. I'm using internal builds .801 and .815 and .823 didn't work.  Maybe there's something I'm missing?

10 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 01 Sep 2011, 09:13 AM
Hello Dan,

I have tested the case and both properties work as expected on my side. Please take a look at the sample and let me know in case of any misunderstanding. 


Kind regards,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
danparker276
Top achievements
Rank 2
answered on 01 Sep 2011, 06:44 PM
Ok, I found out what was going on.  My default TextBlock style seems to over ride the Gridview column settings.

I have a Styles.xaml I call with the following in it:
<Style TargetType="TextBlock">
    <Setter Property="Foreground" Value="{StaticResource BodyTextColorBrush}"/>
    <Setter Property="FontSize" Value="14"/>
    <Setter Property="FontFamily" Value="Segoe UI" />
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Center"/>
</Style>
Removing this from my style sheet makes HeaderTextAlignment="Right" and  TextAlignment="Right" work.  Is there a way around this?
0
Maya
Telerik team
answered on 02 Sep 2011, 11:14 AM
Hi Dan,

You may define the Style you want to be applied for the particular RadGridView in its scope. For example:

  <UserControl.Resources>     
        <Style TargetType="TextBlock">         
            <Setter Property="FontSize" Value="10"/>
            <Setter Property="FontFamily" Value="Georgia" />
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot"
          Background="White"
          DataContext="{StaticResource MyViewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
 
        <telerik:RadGridView Grid.Row="0"
                             Name="clubsGrid"
                             ItemsSource="{Binding Clubs}"
                             AutoGenerateColumns="False"
                             Margin="5">
            <telerik:RadGridView.Resources>
                <Style TargetType="TextBlock">                 
                    <Setter Property="FontSize" Value="14"/>
                    <Setter Property="FontFamily" Value="Segoe UI" />
                    <Setter Property="HorizontalAlignment" Value="Right"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
            </telerik:RadGridView.Resources>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                            Header="Est."
                                            DataFormatString="{}{0:yyyy}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}"
                                            Width="200"
                                            Header="Stadium"
                                            DataFormatString="{}{0:N0}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
                 
<TextBlock Text="My long looong text is here." Grid.Row="1" />        

In this case the Style defined in RadGridView will be applied to all TextBlock-s in it, while the other Style will be applied to the TextBlock outside. 


Greetings,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
danparker276
Top achievements
Rank 2
answered on 02 Sep 2011, 04:54 PM
Yeah, that will work, but I would think that HeaderTextAlignment and TextAlignment in the Grid Column should override what's in the default textblock style.
0
Maya
Telerik team
answered on 03 Sep 2011, 02:05 PM
Hello Dan,

Indeed, you are quite right, setting the HederTextAlignment and TextAlignment properties of the column should override the values set through the style. Actually, we are in the process of investigating the issue. I will get back to you once we resolve it.

Regards,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Vlad
Telerik team
answered on 24 Oct 2011, 10:13 AM
Hello,

 You should use TextAlignment not HorizontalAlignment!

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Arnaud
Top achievements
Rank 1
answered on 28 Apr 2015, 07:49 AM

Hello,

I'm facing the same issue. Setting TextAlignment="Right" in the column definition has no effect over the application wide predefined textblock style. I do not understand Vlad's answer, could you detail it ? 

Arnaud

0
Vanya Pavlova
Telerik team
answered on 30 Apr 2015, 10:42 AM
Hello Arnaud,


Currently the properties defined within the style will take precedence over the TextAlignment property defined for the column. 



Regards,
Vanya Pavlova
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Bob
Top achievements
Rank 1
answered on 16 May 2018, 11:28 PM

I also have an issue with RadGridView alignment to right.  I programmatically add columns to the GridView,

and the result is always left align, even when the 4-th parm is TextAlignment.Right.

 public void AddDgColumn(RadGridView grid, string header, string propertyName,
                    TextAlignment textAlignment = TextAlignment.Left,
                    string columnGroupName = null, string stringFormat = null,
                    EWidthSize eWidth = EWidthSize.NA, double minWidth = 0, double starWidth = 0,
                    bool isReadOnly = true, double width = 0
                    )
        {  // https://www.telerik.com/forums/column-textalignment-isn-t-working
            try
            {
                Binding binding = new Binding(propertyName);
                binding.Mode = BindingMode.OneWay;
                binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

                if (stringFormat != null)
                    binding.StringFormat = stringFormat;

                GridViewDataColumn column = new GridViewDataColumn
                {
                    Header = header,
                    ColumnGroupName = columnGroupName,
                    IsReadOnly = isReadOnly,
                    DataMemberBinding = binding,
                    TextAlignment = textAlignment
                };

Bob Boritz as bboritz@parcoinc.com

0
Stefan
Telerik team
answered on 18 May 2018, 03:43 PM
Hi Bob,

In the provided code snippet the TextAlignment is set to Left. Setting it to Right is working as expected on my end. Attached to my reply you can find a sample application demonstrating this. Can you please take a look at it?

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
danparker276
Top achievements
Rank 2
Answers by
Maya
Telerik team
danparker276
Top achievements
Rank 2
Vlad
Telerik team
Arnaud
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Bob
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or