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

RadGridViewRow's MinHeight issue

13 Answers 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Piyush
Top achievements
Rank 1
Piyush asked on 08 Aug 2011, 12:22 PM
I want to set the RadGridViewRow height as auto means the height should be increase or descrease according to content font size. It Seems, the RadGridViewRow MinHeight is set 24 as default.

I have used my custom GridViewRow template but I haven;t set the MinHeight from anywhere. And I couldn't get the idea fromwhere it has been set.

Any workarround to achive auto RadGridViewRow height would be really appriciated.

Thanks.

13 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 08 Aug 2011, 12:34 PM
Hi Piyush,


You may create a style for the GridViewRows and specify their height in a style setter. The XAML below demonstrates how to set the MinHeight of a row to 12:


<Style TargetType="telerik:GridViewRow" x:Key="RowStyle">   
    <Setter Property="MinHeight" Value="12"/>   
</Style>


Then reference this style to RadGridView and it will work as expected. 

Kind regards,
Vanya Pavlova
the Telerik team

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

0
Piyush
Top achievements
Rank 1
answered on 08 Aug 2011, 02:15 PM
Thanks for the quick reply !

I have tried to apply your suggestion. Unfortunately its behaviour is strange. MinHeight doesn't have any effect if Its set below 26. But Its work as per expectation for MinHeight above 26.

I suspect somewhere from default templates related of GridViewRow the MinHeight is set. It would be great if you can privde me the default templates related with GridViewRow.


Thanks and Regards,
Piyush Sheth
0
Vanya Pavlova
Telerik team
answered on 08 Aug 2011, 02:18 PM
Hello Piyush,



Generally you may extract the default template of any RadGridView element using Microsoft Expression Blend. We ship our themes as separate projects and you may get these files from the Themes folder of your personal installation.


I am attaching you this folder for further reference.


Kind regards,
Vanya Pavlova
the Telerik team

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

0
Piyush
Top achievements
Rank 1
answered on 24 Aug 2011, 07:45 AM

Hello Vanya,

I have looked at the GridView templated relavent with the row Height/MinHeight. Unfortunately I couldn;t find any place where Height/MinHeight defined as 26 px.


Below is simulated code snippets of XAML and CS that I have used to set the font size in GridViewRow cell. Grid display the list of employee with Its Name and Age. In actual case font size is known at runtime and I have implemented it with using RowLoaded()

XAML:
<telerik:RadGridView x:Name="EmployeeList"
                     ColumnWidth="*"
                     IsReadOnly="True"
                     IsFilteringAllowed="False"
                     AutoGenerateColumns="False"
                     RowLoaded="EmployeeList_RowLoaded">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Name">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>                         
                        <TextBlock Text="{Binding Name}" TextTrimming="WordEllipsis"/>                         
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn Header="Age">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Age}" TextTrimming="WordEllipsis"/>                      
                </DataTemplate>
            </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

CS:
private void EmployeeList_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if (!(e.Row is GridViewHeaderRow) && !(e.Row is GridViewFooterRow) && !(e.Row is GridViewNewRow))
{
if (e.DataElement != null)
{
for (int cellCount = 0; cellCount < e.Row.Cells.Count; cellCount++)
{
TextBlock cellContentTextBlock = e.Row.Cells[cellCount].FindChildByType<TextBlock>();
if (cellContentTextBlock != null)
{
if (rowCount % 2 == 0)
cellContentTextBlock.FontSize = 8;
else
cellContentTextBlock.FontSize = 30;
}
}
rowCount++;
}
}
}
 
The output of above code is display in attached file. you can see that if the font size is 30 that row height increased. but for font size 8 the row height is 26 px. I would like to decreased it below 26.

Any work arround to achieve it would be really appriciated.

Thanks & Regards,
Piyush Sheth
0
Vanya Pavlova
Telerik team
answered on 24 Aug 2011, 09:10 AM
Hello Piyush,

 

As it was proposed in my previous post If you may define a style in a UserControl's ResourceCollection and set the MinHeight property of a row the picture then the RowHeight will be changed correspondingly:


<UserControl.Resources>
    <Style TargetType="telerik:GridViewRow">
        <Setter Property="MinHeight" Value="2"/>
    </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
        <telerik:RadGridView x:Name="EmployeeList"
                     ColumnWidth="*"
                     IsReadOnly="True"
                     IsFilteringAllowed="False" RowHeight="1"
                     AutoGenerateColumns="False" ItemsSource="{Binding Collection}"
                    RowLoaded="EmployeeList_RowLoaded">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" TextTrimming="WordEllipsis"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Age">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Age}" TextTrimming="WordEllipsis"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>


Within RadGridView's RowLoaded event handler you iterate over the elements defined in a CellTemplate which is not a good approach, since it will messes up with RadgridView's virtualization. The recommended approach to achieve this result is to operate directly over the data item, rather than over the visual elements. You should use StyleSelectors instead, please check our demos for further reference.  


Kind regards,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Piyush
Top achievements
Rank 1
answered on 24 Aug 2011, 11:53 AM
Hello Vanya,

I have tried your suggestion in my actual code (with custom template) and in the sample ( with default template) that I have pasted in previous post. The Unfortunately MinHeight property is not working. Infact if I set grater than 26 then it is giving effect but not below 26.


Actually I wanted to send you the POC for the same but seems only image files are allowed to upload in forum. Please tell me if  there is any other way arround by which I can send you the solution sothat you can have better idea. And also send it back to me with work arround that give effect of Row height below 26.

Thanks & Regards,
Piyush Sheth
0
Vanya Pavlova
Telerik team
answered on 24 Aug 2011, 02:30 PM
Hi Piyush,

 

You may submit a new support ticket from Your Account -> GetSupport, following this link.
There you may attach your application which we may use for local testing and debugging. It could be great if you can attach your StyleSelector example and we may see what might be wrong. 
Any additional information about the grid version you used will be highly appreciated as well. 



Kind regards,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Robin Witteveen
Top achievements
Rank 1
answered on 25 Aug 2011, 10:37 AM
Hello Vanya,

I am generating the support ticket to send you the sample solution. I thinking to also send you attached solution directly.

can you please give me your email address sothat I can add it in CC ?

Thanks & Regards,
Piyush Sheth
0
Vanya Pavlova
Telerik team
answered on 25 Aug 2011, 10:41 AM
Hello Robin Witteveen,



It is enough to tell me ticket ID and I will find it.



All the best,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Robin Witteveen
Top achievements
Rank 1
answered on 25 Aug 2011, 10:46 AM
Ticket ID:  457679


0
Vanya Pavlova
Telerik team
answered on 25 Aug 2011, 12:55 PM
Hello Robin,

 

I have already replied to your support ticket. 


All the best,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Piyush
Top achievements
Rank 1
answered on 26 Aug 2011, 06:45 AM
Hello Vanya,

Thanks for the solution. But in my actual implementation the FontSize is known at runtime with very wide range from  8 to 72. So I think, Its not wise to set the RowHeight explicitly according to font size. It would be great if there is any other work arround to achieve it.

I am wondering, why the "MinHeight=2" property setting solution that you have suggested in your earlier posts not working in my sample code that I have sent to you in support Tickert ID = 457679

   

Thanks & Kind Regards,
Piyush Sheth
0
Vanya Pavlova
Telerik team
answered on 31 Aug 2011, 12:00 PM
Hello Piyush,

 
Indeed in your case the better approach is to explicty set the RowHeight of RadGridView to a fixed Value.
As I tried to suggest in my previous reply it is better to define a StyleSelector which will do the trick. 
You may define as much styles as you need to achieve the desired result. 


 

All the best,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Piyush
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Piyush
Top achievements
Rank 1
Robin Witteveen
Top achievements
Rank 1
Share this question
or