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

Right-justifying currency in a column

8 Answers 133 Views
GridView
This is a migrated thread and some comments may be shown as answers.
GEB
Top achievements
Rank 1
GEB asked on 08 Feb 2010, 05:26 PM
I am using column formatting to display a column as currency.  I would like to right-justify the contents of this column.  Is there any way to specify that the contents of a column should be right-justified within that column?

8 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 09 Feb 2010, 07:46 AM
Hello GEB,

You just have to create a simple GridViewCell style and set the HorizontalAlignment property to Right. For example:

<telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}">
    <telerik:GridViewDataColumn.CellStyle>
        <Style TargetType="gridView:GridViewCell">
            <Setter Property="HorizontalAlignment" Value="Right"/>
        </Style>
    </telerik:GridViewDataColumn.CellStyle>
</telerik:GridViewDataColumn>


Kind regards,
Milan
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Kevin Happe
Top achievements
Rank 1
answered on 20 May 2010, 03:52 PM
Can you give an example of how I would center or right align a cell in c#?  My columns are added dynamically.
0
Vlad
Telerik team
answered on 20 May 2010, 03:55 PM
Hi,

Here is an example:

RadGridView1.Columns.Add(new GridViewDataColumn() { DataMemberBinding = new Binding("CustomerID"), TextAlignment = TextAlignment.Right });


Best wishes,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Happe
Top achievements
Rank 1
answered on 20 May 2010, 04:01 PM
I should have given you some more information.  I am having a problem with a checkbox column,  by default it is left aligning and I want to be center aligned.   I tried using textalignment and it didnt change anything.
0
Vlad
Telerik team
answered on 20 May 2010, 04:06 PM
Hello,

Here is another example:

           var style = new Style(typeof(GridViewCell));
            var setter = new Setter(GridViewCell.HorizontalContentAlignmentProperty, HorizontalAlignment.Right);
            style.Setters.Add(setter);

            RadGridView1.Columns.Add(new GridViewDataColumn()
            {
                DataMemberBinding = new Binding("CustomerID"),
                CellStyle = style
            });

If you prefer you can define the style as resource instead.

Best wishes,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Happe
Top achievements
Rank 1
answered on 20 May 2010, 04:16 PM
Awesome, That worked like a champ and gives me a good example of setting cell styles at runtime.
Thanks
Kevin Happe
0
GEB
Top achievements
Rank 1
answered on 22 May 2010, 01:29 PM
Make certain that you set the HorizontalContentAlignment property, as opposed to HorizontalAlignment.  Both will cause the text to be right-justified.  However, double-click will not work properly if HorizontalAlignment is set instead of HorizontalContentAlignment.  This is contrary to the response given on 2/9/2010.


0
Charles
Top achievements
Rank 2
answered on 01 Mar 2011, 10:16 PM
I had this same issue and attempted the solution given above. It didn't work. I received an error:

Failed to create a 'System.Type' from the text 'gridView:GridViewCell'. [Line: 80 Position: 47]

That is the position where the TargetType is defined.
Tags
GridView
Asked by
GEB
Top achievements
Rank 1
Answers by
Milan
Telerik team
Kevin Happe
Top achievements
Rank 1
Vlad
Telerik team
GEB
Top achievements
Rank 1
Charles
Top achievements
Rank 2
Share this question
or