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

TextAlignment lost after Conversion

8 Answers 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 07 Jun 2010, 09:25 PM
Hello-
I have a series of numbers being displayed in a RadGridView which need to be conditionally formatted.  It's financial data, so positive numbers need to be green and negative should be red and in parentheses.  I used Pavel Pavlov's approach to data conversion (using ConditionalFormattingBehavior : Behavior<RadGridView> and creating new bindings).  However, when I do this, the TextAlignment property gets reset.  I need the data to be right-justified.  I tried doing it in code (e.Row.Cells[2].TextAlignment = TextAlignment.Right;) but, it tells me that Telerik.Controls.GridView.GridViewCellBase.TextAlignment is obsolete/deprecated. 

Is there another way to reset the TextAlignment?

I'm using VS2010, SL4 & RadGridView v2.0.50727

Thanks!
-Jeremy

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 Jun 2010, 06:28 AM
Hi Jeremy,

Please check our new examples related to conditional styling and templates:
http://demos.telerik.com/silverlight/#GridView/Selectors/DataTemplateSelectors/CellTemplateSelector
http://demos.telerik.com/silverlight/#GridView/Selectors/StyleSelectors/CellStyleSelector

If your columns are plain GridViewDataColumns with no templates you can cast cell.Content to TextBlock and apply desired formatting. Other possible approach will be to load different templates (with different TextBlock settings) using CellTemplateSelector column property.

Regards,
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
Jeremy
Top achievements
Rank 1
answered on 08 Jun 2010, 05:11 PM
thank you for your reply!  There is still some confusion.

Where is UnitPriceConverter getting defined?
Where is ConditionalDataTemplateSelector defined?
Where is the logic for defining which template to use?

Also, are there any examples of casting cell.Contents?

Thanks!
Jeremy
0
Jeremy
Top achievements
Rank 1
answered on 11 Jun 2010, 02:34 AM
Is there any update on this?

Thanks!
-Jeremy
0
Vlad
Telerik team
answered on 14 Jun 2010, 06:43 AM
Hello,

 Please download our demos to check the source code of this examples! Here is an example of casting:

((TextBlock)cell.Content)

Greetings,
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
Jeremy
Top achievements
Rank 1
answered on 17 Jun 2010, 06:43 PM
Thank you for the update, Vlad!

I have looked at the links you provided both online and downloaded the examples, however, the Example.cs looks overly simplified.  Shouldnt there be more to it?

Thanks,
Jeremy
0
Jeremy
Top achievements
Rank 1
answered on 18 Jun 2010, 02:04 AM
I get this error when casting...

((TextBlock)e.Row.Cells[1].Content).TextAlignment = TextAlignment.Right;

Unable to cast object of type 'System.String' to type 'System.Windows.Controls.TextBlock'.

Thoughts?
0
Vlad
Telerik team
answered on 18 Jun 2010, 06:20 AM
Hi,

 Can you post this cell column declaration? Is it GridViewDataColumn?

Regards,
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
Dipti
Top achievements
Rank 1
answered on 30 Jan 2012, 07:57 AM
Hi Jeremy, did you find a solution to this issue? I have the exact same requirement. 

Problem Description:
I have columns defined in my GridView for which I am using CellTemplateSelector. But when i do so I am unable to align text to "Right" in my tetxbox. Text Alignment value is not used.

<telerik:GridViewColumn.CellTemplateSelector>
    <local:D0_30Template>
        <local:D0_30Template.EmptyDataTemplate>
            <DataTemplate>
                <TextBlock TextAlignment="Right" ></TextBlock>
            </DataTemplate>
        </local:D0_30Template.EmptyDataTemplate>
    </local:D0_30Template>
</telerik:GridViewColumn.CellTemplateSelector>

Tags
GridView
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jeremy
Top achievements
Rank 1
Dipti
Top achievements
Rank 1
Share this question
or