GridViewComboBoxColumn Text Alignment

4 posts, 1 answers
  1. Lee Weisenberger
    Lee Weisenberger avatar
    72 posts
    Member since:
    Nov 2009

    Posted 21 Jul 2010 Link to this post

    How do you change the text alignment for the text displayed in a GridViewComboBoxColumn in a RadGridView?

    I've tried to set TextAlignment="Right" but the text in the combo is always left aligned.

    Thanks.


  2. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 22 Jul 2010 Link to this post

    Hello Lee Weisenberger,

    Setting HorizontalContentAlignment instead of HorizontalAlignment will resolve the problem. 

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


    Best wishes,
    Milan
    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. DevCraft banner
  4. Vic
    Vic avatar
    36 posts
    Member since:
    Aug 2012

    Posted 09 Sep 2014 Link to this post

    When specifying a CellStyle as suggested above (using Build 2014.2.0617), I find that it also affects the placement of the editor control (RadComboBox) so that it no longer stretches to fit the width of the cell.  Specifying an EditorStyle or CellEditTemplate to override this behavior has no effect.  Is there another solution?

    I am trying to avoid creating a CellTemplate for this column as it complicates the databinding.

    Thanks..
  5. Yoan
    Admin
    Yoan avatar
    1070 posts

    Posted 12 Sep 2014 Link to this post

    Hi,

    I would suggest you to use a regular GridViewDataColumn and place a RadCombobox in its CellEditTemplate. Then you can set the TextAlignment property of the column to "Right":
    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"
     UniqueName="Name"
     TextAlignment="Right"
                        <telerik:GridViewDataColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox ItemsSource="{Binding Clubs,Source={StaticResource MyViewModel}}"
                 HorizontalContentAlignment="Stretch"
                 SelectedIndex="0"
                 SelectedValuePath="Name"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellEditTemplate>
                    </telerik:GridViewDataColumn>


    Please give it a try and let me know how it works for you.

    Regards,
    Yoan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top