Textbox HorizontalContentAlignment

4 posts, 0 answers
  1. Sven
    Sven avatar
    2 posts
    Member since:
    Jul 2011

    Posted 03 May 2012 Link to this post

    How do I get a TextBox in a DataTemplate to 100% of the column width?

    <telerik:GridViewDataColumn Header="Enter SPGR" SortMemberPath="SPGR" DataMemberBinding="{Binding SPGR}"                     HeaderCellStyle="{StaticResource WriteGridViewHeaderCellStyle}">
        <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                    <TextBox Text="{Binding SPGR, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
                         HorizontalAlignment="Right" VerticalAlignment="Center" HorizontalContentAlignment="Stretch" IsReadOnly="{Binding IsProcessed}"/>
            </DataTemplate>
        </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>

    This ends up here: http://twitpic.com/9gno9l 

    But I want the TextBox not just the width of the current text, it should take the width of the column. How?

    Best regards
    Sven
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 May 2012 Link to this post

    Hi,

     You will need to change the Padding for the GridViewCell.

    <Style TargetType="telerik:GridViewCell">
               <Setter Property="Padding" Value="0"/>
    </Style>

    I hope that this is helpful.

    Greetings,
    Didie
    the Telerik team

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

  3. Sven
    Sven avatar
    2 posts
    Member since:
    Jul 2011

    Posted 03 May 2012 Link to this post

    No, it does not help. The initial size is the same.

    Strange is (with or without Padding Setting), that the 100% TextBox becomes visible, when I click left of the TextBox but not if I click in the TextBox.

    Sven
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 04 May 2012 Link to this post

    Hello,

    I have checked your case. There are two reasons for this behaviour:

    1. You have set HorizontalAlignment="Right"
    2. You have defined only CellTemplate, without CellEditTemplate. The TextBox that you see when you click next to your TextBox is actually the editor when the Cell goes into Edit mode. 

    To resolve it, you should:
    1. Set HorizontalAlignment="Stretch"
    2. Set the column to be ReadOnly.
     For example:
    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"  >
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Name, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}"
                         HorizontalAlignment="Stretch" VerticalAlignment="Center" HorizontalContentAlignment="Stretch" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>

    I hope that this is what you need.


    Greetings,
    Didie
    the Telerik team

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

Back to Top