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

Textbox width in a Cell Template

3 Answers 144 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 25 Mar 2012, 06:28 AM
I have a cell template that contains several items:   Two images and one text box.

The images optionally are displayed based on a condition and the text box is always visible.   However, I cannot seem to get the with to stretch to the full size of the cell template.   I have tried both WrapPanels and Grids and neither works.

I have found that it appears to be related to the fact that I am not specifically setting the width of the cell.   When I set it to some value, then the text box seems to stretch as expected, but unfortunately, I need the width of the column to be auto sized based on the content (i.e. if the images need to be shown, then it should auto expand).

What can I do to make the text box expand to the full width of the gridview cell?

Or, is there a better way to do what I am attempting?

Here is my XAML code:

 

<telerik:GridViewDataColumn Header="Base Price" HeaderTextAlignment="Center" MinWidth="50">
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Image Source="/PriceBook;component/Images/Pencil.png" Grid.Column="0"
                       Visibility="{Binding BasePrice.IsPriceChanged, Converter={StaticResource VisibilityConverter}}" />
                <Image Source="/PriceBook;component/Images/Override.png" Grid.Column="1"
                       Visibility="{Binding BasePrice.IsPriceOverride, Converter={StaticResource VisibilityConverter}}" />
                <TextBox Grid.Column="2" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
                         Text="{Binding BasePrice.Current, Mode=TwoWay, Converter={StaticResource PriceConverter}}"
                         BorderThickness="0" Background="Transparent" Foreground="{Binding BasePrice.Foreground}"
                         ToolTipService.ToolTip="{Binding BasePrice.ToolTipText}" TextAlignment="Right"></TextBox>
            </Grid>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>



3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 26 Mar 2012, 12:26 PM
Hi,

 As I understand you want to have the column auto expanded so that both the Images and the TextBox to be shown with their full content(the column width is the exact width so that all the content inside is visible). I have tested your code snippet and as a result I got this result. The GridViewCell expands so that the full content in the TextBox is visible.  I have tested the Q1 2012 version of the controls.

If I have somehow misunderstood your problem, please let me know where I am wrong.

Greetings,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Steven
Top achievements
Rank 1
answered on 28 Mar 2012, 06:42 AM
I am using q3 2011 version. I am concerned with upgrading at this point as I don't want to encounter issues with upgrading. Can you verify if that was an issue that was fixed in later releases? If so, I will have to see if I can use the newer version. Thanks.
0
Dimitrina
Telerik team
answered on 30 Mar 2012, 12:09 PM
Hi,

 I have tested the same code with version Q3 2011 and still the GridViewCell expands so that the full content in the TextBox is visible. So I cannot confirm anything related to this issue.
I have attached the test project for your reference. Please note that I have not used any converters as I do not know how yours are defined.

All the best,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Steven
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Steven
Top achievements
Rank 1
Share this question
or