TextAlignment lost after Conversion

9 posts, 0 answers
  1. Jeremy
    Jeremy avatar
    16 posts
    Member since:
    May 2010

    Posted 07 Jun 2010 Link to this post

    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
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Jun 2010 Link to this post

    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.
  3. Jeremy
    Jeremy avatar
    16 posts
    Member since:
    May 2010

    Posted 08 Jun 2010 Link to this post

    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
  4. Jeremy
    Jeremy avatar
    16 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    Is there any update on this?

    Thanks!
    -Jeremy
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Jun 2010 Link to this post

    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.
  6. Jeremy
    Jeremy avatar
    16 posts
    Member since:
    May 2010

    Posted 17 Jun 2010 Link to this post

    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
  7. Jeremy
    Jeremy avatar
    16 posts
    Member since:
    May 2010

    Posted 17 Jun 2010 Link to this post

    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?
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Jun 2010 Link to this post

    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
  9. Dipti
    Dipti avatar
    37 posts
    Member since:
    Dec 2011

    Posted 30 Jan 2012 Link to this post

    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>

Back to Top