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

Textbox HorizontalContentAlignment

3 Answers 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sven
Top achievements
Rank 1
Sven asked on 03 May 2012, 08:07 AM
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

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 03 May 2012, 09:57 AM
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 >>

0
Sven
Top achievements
Rank 1
answered on 03 May 2012, 10:15 AM
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
0
Dimitrina
Telerik team
answered on 04 May 2012, 03:22 PM
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 >>

Tags
GridView
Asked by
Sven
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Sven
Top achievements
Rank 1
Share this question
or