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
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 >>
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
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 >>
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
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 >>
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
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.
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 >>
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
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 >>
I have already replied to your support ticket.
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 >>
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
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.
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 >>