
Basically, I need to recalculate my app's hight based on the number or records in the grid AND make sure the height increase/decrease is factored in when a record is expanded/collapsed. I actually pass this value into a hidden field on my aspx page.
Using the SizeChanged does not exactly solve the problem. I've also tried a combination of child control's events (actually, I use RadTabControl inside of the DataTemplate io the HierarchyChildTemplate in the GridView) and the SizeChanged event on the GridView, but still to no avail (for example, I can use SizeChanged on the RadTabControl, but it only captures expanding, and not collapsing event - after it's loaded into the control, it stays there even if you collapse it).
Any suggestions would be greatly appreciated.
Thank you!
-VK.
9 Answers, 1 is accepted
You may take a look at our online documentation giving more information about the events fired on loading/unloading the RowDetails.
Let me know, if you need any further assistance.
Maya
the Telerik team

I've seen the documentation you are referring to. I couldn't use the approach described there though. I ended up creating a custom event handler on the MouseLeftButtonDownEvent where I wrote some logic to determine whether the incoming e.OriginalSource is the cell with the + or - button or not. If the e.Original Source is in fact the expand/collapse area, I add/subtract (a decision here is made based on parentRow.IsExpanded) 1 to the number of expanded profiles (a global variable), which later down the chain of events translates into a specific increment/decrement (in pixels) to the height of my control. This is an accurate, yet ugly way to solve the problem. However, I couldn't find a better one as of yet.
Looking at your explanations, it seems to me that it will be appropriate to use the RowDetailsVisibilityChanged event that fires when the RowDetails turn from visible to collapsed and vice versus. Thus you may substitute the creation of a custom event handler and the examination of the toggle button's state. However, as you are saying that you could not use the approaches described in the documentation, I would need a bit more details about your application. Why is it inappropriate for you to handle this event ? Any specific and relevant code-snippet would be of a help.
Maya
the Telerik team

I've tried adding RowDetailsVisibilityChanged event to the grid, but it is never fired in my app. I'm sticking with my approach of using the OnGridMouseDown event instead.
Thanks!
Basically, there should be no obvious reason for the RowDetailsVisibilityChanged event not to be fired. So, if you have any further difficulties with handling the OnGridMouseDown and need another possible approach, I would need slightly more information about your application and its settings.
Maya
the Telerik team

I've checked all my code on the radGridView and I have to agree that the "RowDetailsVisibilityChanged" event doesn't fire when I use my generic class as a DataSource.
In fact I have to manually add any eventHandlers to the rows, otherwise the onclick events don't fire either.
I'm assuming it's because I'm using a generic class object as the datasource.
I've tried using the event handler "GridViewRow.IsExpandedChangedEvent".
Unfortunately when this event is raised the DesiredSize.Height has not changed yet.
In fact, none of the properties have changed at all.
What I would like is a RowDetailsVisibilityChanged event on the Telerik.Windows.Controls.GridView.GridViewRow.
So that I can manually add an event handler.

You've said that "Basically, there should be no obvious reason for the RowDetailsVisibilityChanged event not to be fired."
Well, I've had breakpoints set up, but they were never reached.
Again, I've solved the problem by using another approach. Below is a description of the problem I was facing and the solution that worked for me.
Note: I'm using WCF RIA to pull data. I'm adding grid columns programmatically.
The problem: the control does not resize itself properly when more/less records are loaded into the grid and when a child element is expanded/collapsed. The size (height) of the control has a max and min caps too. Usually, this is not a problem. However, this control is loaded inside of another control (accordion) and without proper size handling a portion of this control is truncated.
A solution: I'm using grid's DataLoaded event to catch its resizing driven by a new set of data flowing from my data model (and I have a function that calc ulates and sets the size of the control based on the number of records). This takes care of the first part of the problem. To handle the increase/decrease in size of the child element(s), I've tried a whole bunch of events, but all failed for me. The one I'm actually using is the MouseLeftButtonDownEvent event that I set in my constructor as follows:
rgvMainGrid.AddHandler(FrameworkElement.MouseLeftButtonDownEvent, new
MouseButtonEventHandler(OnGridMouseDown), true);
As I've stated before in my earlier posts in this thread, inside of the OnGridMouseDown I determine if the "+" button has been pressed, and if so, I increment/decrement the count of opened child elements on the page and use it as a factor in my size calculations. This approach seems to be working for me, but is a bit of a hack and sure is not pretty.
Here is the layout (the RowDetailsVisibilityChanged has been already removed at this point):
<Grid x:Name="LayoutRoot"...>
...
...
<telerik:RadBusyIndicator Grid.Row="1" x:Name="busyIndicator"
BusyContent="Loading data...."
Background="White"
VerticalAlignment="Top" >
<telerik:RadGridView x:Name="rgvMainGrid" SizeChanged="rgvMainGrid_SizeChanged"
DataLoaded="rgvMainGrid_DataLoaded" AutoGenerateColumns="False" ItemsSource="{Binding v_Data_Search}"........>
<telerik:RadGridView.ChildTableDefinitions>
<telerik:GridViewTableDefinition>
</telerik:GridViewTableDefinition>
</telerik:RadGridView.ChildTableDefinitions>
<telerik:RadGridView.HierarchyChildTemplate>
<DataTemplate>
<telerik:RadTabControl BackgroundVisibility="Collapsed" x:Name="RadTabControl1" VerticalAlignment="Center"
Background="Transparent">
<telerik:RadTabItem DataContext="{Binding}" Header="Main" Visibility="Collapsed"
Tag="tabMain"
Foreground="Black">
<Grid Width="Auto" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="20" />
<RowDefinition Height="24" />
<RowDefinition Height="15" />
<RowDefinition Height="15" />
<RowDefinition Height="15" />
<RowDefinition Height="15" />
<RowDefinition Height="15" />
<RowDefinition Height="15" />
<RowDefinition Height="15" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.Background>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0.1,1">
<GradientStop Color="#99FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Border Grid.Column="0" Grid.Row="0" Grid.RowSpan="10"
VerticalAlignment="Top" HorizontalAlignment="Stretch"
Height="115" Width="115" Margin="15"
BorderThickness="1" CornerRadius="1" BorderBrush="#FFE8E8E8">
<Border Margin="0" BorderThickness="1,1,1,1" CornerRadius="0,0,0,0" BorderBrush="Gainsboro">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#33FFFFFF" Offset="1"/>
<GradientStop Color="#00000000"/>
<GradientStop Color="#7FFFFFFF" Offset="0.17"/>
<GradientStop Color="#66FFFFFF" Offset="0.18"/>
</LinearGradientBrush>
</Border.Background>
<Image x:Name="imgPic" DataContext="{Binding ID}" Loaded="imgPic_Loaded" >
<Image.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.935"/>
<GradientStop Offset="1"/>
<GradientStop Color="#00000000"/>
<GradientStop Color="Black" Offset="0.113"/>
</LinearGradientBrush>
</Image.OpacityMask>
</Image>
</Border>
</Border>
<TextBlock Text="{Binding Name}" FontWeight="Bold" FontFamily="Verdana" FontSize="14"
Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" />
<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2">
<TextBlock Text="{Binding Title}" FontWeight="Bold" FontFamily="Verdana" FontSize="12" />
<TextBlock Text=", " FontWeight="Bold" FontFamily="Verdana" FontSize="12" />
<TextBlock Text="{Binding Office}" FontWeight="Bold" FontFamily="Verdana" FontSize="12" />
</StackPanel>
<TextBlock Text="Phone (Internal): " FontWeight="Bold" Grid.Row="3" Grid.Column="1" />
<TextBlock Text="{Binding InternalDial}" Grid.Row="3" Grid.Column="2" />
<TextBlock Text="Phone (External): " FontWeight="Bold" Grid.Row="4" Grid.Column="1" />
<TextBlock Text="{Binding DirectDial}" Grid.Row="4" Grid.Column="2" />
<TextBlock Text="Phone (Mobile): " FontWeight="Bold" Grid.Row="5" Grid.Column="1" />
<TextBlock Text="{Binding MobilePhone}" Grid.Row="5" Grid.Column="2" />
<TextBlock Text="Fax: " FontWeight="Bold" Grid.Row="6" Grid.Column="1" />
<TextBlock Text="{Binding WorkFax, Converter={StaticResource FormatPhoneNumber}}"
Grid.Row="6" Grid.Column="2" />
<TextBlock Text="Email: " FontWeight="Bold" Grid.Row="7" Grid.Column="1" />
<HyperlinkButton Content="{Binding Email}" NavigateUri="{Binding Email, ConverterParameter=mailto:\{0\},
Converter={StaticResource FormatProfileImage}}" Grid.Row="7" Grid.Column="2" />
</Grid>
</telerik:RadTabItem>
</telerik:RadTabControl>
</DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
</telerik:RadGridView>
</telerik:RadBusyIndicator>
</Grid>

Private
Sub
gvMain_DataLoading(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Windows.Controls.GridView.GridViewDataLoadingEventArgs)
Handles
gvMain.DataLoading
Dim
dataControl
As
GridViewDataControl =
DirectCast
(sender, GridViewDataControl)
If
dataControl.ParentRow IsNot
Nothing
Then
'dataControl is the child gridview
dataControl.ShowGroupPanel =
False
dataControl.IsReadOnly =
True
gvMain.
AddHandler
(gvMain.RowDetailsVisibilityChanged,
New
GridViewRowDetailsEventArgs(dataControl.ParentRow, dataControl))
End
If
End
Sub
Error 15 Value of type 'Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs' cannot be converted to 'System.Delegate'.
Can someone please help me with the correct formatting for this?
The RowDetailsVisibilityChanged is not a routed event, consequently you cannot add a handler in the way you attempt. So, in order to suggest any further on your issue, I would need more details about your application. Any relevant code-snippet would be helpful.
Maya
the Telerik team