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

[Solved] Frame Resize

3 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jaco
Top achievements
Rank 1
Jaco asked on 19 Oct 2010, 01:25 PM
I've been sitting with this for a while now and have been unable to solve the problem.

What I would like to do:
When expanding a heirarchy I would like to fire an event that sends the new "ScrollHeight" of the grid control to a javascript function. The function will then resize the frame containing my GridControl, therefore eliminating the scollbar and the need for it.

a) I've added an event handler "GridViewRow.IsExpandedChangedEvent".
Unfortunately when this event is executed the DesiredSize.Height has not changed yet. In fact, none of the properties have changed at all.

I've also tried several other solutions, including "OnRowLoad()", "DockingPanel", "PropertyChangedEvent"(for the height) and more.

Could you please provide me with a solution for this?

3 Answers, 1 is accepted

Sort by
0
Jaco
Top achievements
Rank 1
answered on 20 Oct 2010, 01:46 PM
I've had the idea to manually add the Event Handler for the RowDetailsLoaded Event:

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?
0
Milan
Telerik team
answered on 21 Oct 2010, 08:59 AM
Hi Jaco,

There are several problems with this approach. The first problem is that the DesiredHeight property will not give you accurate results. The second one is that the IsExpandedChanged event is fired before the grid has rendered the new UI - the new desired size is unknown at that point. 

To solve the problem you should first use another property that gives more accurate results. This property is called ExtentHeight and can be found though the ScrollViewer of the grid:

var scrollviewer = this.clubsGrid.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();
var rowsHeight = scrollviewer.ExtentHeight;
// rowsHeight will only account for the height of all rows 
// the height of items that are outside the ScrollViewer (like header row ) is not included

To solve the second problem you could use DispatcherTimer as demonstrated here:

private void playersGrid_RowIsExpandedChanged(object sender, RowEventArgs e)
{
    // delay execution of code
    this.Dispatcher.BeginInvoke(() =>
    {
        var scrollviewer = this.clubsGrid.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();
        var rowsHeight = scrollviewer.ExtentHeight;
        // rowsHeight will only account for the height of all rows 
        // the height of items that are outside the ScrollViewer (like header row ) is not included
  
    });
}

Hope this helps.


Greetings,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jaco
Top achievements
Rank 1
answered on 21 Oct 2010, 03:19 PM
Eh, don't worry about it... Eventually my boss allowed me to do the size calculation by rowCount...
Even though it's a horrid piece of code, it works. (3 days of suffering, trying to solve what should be a simple problem)

 

 

Private Sub IsExpandedChangedEvent(ByVal sender As Object, ByVal e As Windows.RoutedEventArgs)
    Dim MasterRowsHeight As Integer = 0
    Dim ExpandedRowHeight As Integer = 0
    MasterRowsHeight = (gvMain.Items.ItemCount * 25) + 105
    For Each Row As GridViewRow In gvMain.ChildrenOfType(Of GridViewRow)()
        If Row.IsExpanded And Row.IsHitTestVisible Then
            Dim MyAssetCategory = Row.ChildrenOfType(Of GridViewCell)().Where(Function(c) c.Column.UniqueName = "AssetCategoryName").First().Value
            For Each Item In gvMain.Items
                If Item.AssetCategoryName = MyAssetCategory Then
                    If Not Item.DetailLines Is Nothing Then
                        ExpandedRowHeight += (Item.DetailLines.Count() * 25) + 55
                    End If
                    Exit For
                End If
            Next
        End If
    Next
    RaiseEvent WindowSizeChanged(sender, New CustomWindowSizeChangedHandler(MasterRowsHeight + ExpandedRowHeight))
End Sub

 

The problem with your code is that I don't have an event that fires AfterExpanded.
The RowDetailsVisibilityChanged event doesn't even fire in my code.
AND when the RowIsExpandedChanged event is fired, none of the variables have changed at all, it fires first, before the size of the grid changes or the row is expanded.

Tags
GridView
Asked by
Jaco
Top achievements
Rank 1
Answers by
Jaco
Top achievements
Rank 1
Milan
Telerik team
Share this question
or