We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PivotGridControl Resizetofit

Hi,

I have a PivotGid where certain columns resize to fit after the users changes the grid fields with the PivotTableFieldList. I got this working using the TableModel.ColWidthsChanged event, but maybe there is another event better suited for this??

My problem: the ResizeToFit command still makes the row expander columns too small -> is there a way to force this command to create more space??

I have this code linked to a button which gives the result I want EXCEPT that I would like this linked to an event and not to a button:

       With RbrStandenPivot
            If .PivotRows.Count > 0 Then
                .TableModel.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, .PivotRows.Count), GridResizeToFitOptions.NoShrinkSize)
            End If
            For ColNo = 1 To .PivotRows.Count
                Dim OldWidth As Integer = .TableControl.GetColWidth(ColNo)
                .TableControl.SetColWidth(ColNo, ColNo, OldWidth + 50)
            Next
        End With

I have tried several events, but either the changes are overruled or recursion occurs with an error...

Thanks a lot! Cheers,

Matthijs

 


6 Replies

MG Mohanraj Gunasekaran Syncfusion Team February 20, 2017 12:58 PM UTC

Hi Matthijs,  
  
Thanks for using Syncfusion products.  
 
In order to change the width when make the changes in PivotTableFieldList, you can use the PivotSchemaDesigner.SchemaChanged property. If you try to change the Column widths ColWidthsChanged event this event triggers recursively so do not use this event to change the column widths. Please refer the below code example and refer the attached sample, 
 
Code example 
AddHandler Me.pivotGridControl1.PivotSchemaDesigner.SchemaChanged, AddressOf PivotSchemaDesigner_SchemaChanged 
Private Sub TableModel_QueryColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs) 
    Dim _with1 = Me.pivotGridControl1 
    If _with1.PivotRows.Count > 0 Then 
      _with1.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Cols(1, _with1.PivotRows.Count), GridResizeToFitOptions.NoShrinkSize); 
    End If 
    For ColNo As Integer = 1 To _with1.PivotRows.Count 
    Dim OldWidth As Integer = _with1.TableControl.GetColWidth(ColNo) 
    Me.pivotGridControl1.TableModel.ColWidths(ColNo) = OldWidth + 50 
    Next ColNo 
End Sub 
 
 
Sample link: PivotGrodControl 
 
Regards, 
Mohanraj G. 
 



MH Matthijs Huisman February 20, 2017 02:24 PM UTC

Hi,

thank you for your answer, you set me on the right track!

With your advice I solved my problems as follows:

I use the PivotSchemaDesigner.SchemaChanged event to track changes in the grid initiated by the user, including changes in the filter expressions (see my question with ID 128972)

NB: the SchemaChanged event only works with the ShowPivotTableFieldList set to true BUT now I use the PivotRows.CollectionChanged event to track changes to the rows and apply the ResizeToFit solution (whether the PivotTableFieldList is visible or not).

So it all works fine now! Thanks for your help!!


MH Matthijs Huisman February 20, 2017 02:50 PM UTC

Sorry, I was too quick...

The PivotRows.CollectionChanged event does not work the way I thought (the ResizeToFit gets overuled afterwards) -> BUT I worked around this by adding the ResizeToFit solution to the PivotRows.CollectionChanged handler (when the PivotTableFieldList is visible and the user chooses the fields).

When the PivotTableFieldList is disabled (and the code determines the fields) I use the QueryColWidth event so set to widths. NB: I remove / add the handler for this event when the PivotTableFieldList is enabled / disabled.

Thanks!


MG Mohanraj Gunasekaran Syncfusion Team February 21, 2017 05:35 PM UTC

Hi Matthijs, 
 
Thanks for your update. 
 
In order to achieve your scenario, you can use the Boolean variable in PivotSchemaChanged event to check whether PivotSchema changed or not. If you disable the PivotTableFieldList, the PivotSchemaDesigner is null so you can check this that property in QueryColWidth event. So no need to remove(unwire) the QueryColWidth event handler. Please refer the below code example and refer the below attached sample, 
 
Code example 
 
AddHandler Me.pivotGridControl1.PivotSchemaDesigner.SchemaChanged, AddressOf PivotSchemaDesigner_SchemaChanged 
AddHandler Me.pivotGridControl1.TableModel.QueryColWidth, AddressOf TableModel_QueryColWidth 
 
Private pivotSchemaChanged As Boolean = False 
 
Private Sub PivotSchemaDesigner_SchemaChanged(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.PivotAnalysis.SchemaChangedEventArgs) 
                pivotSchemaChanged = True 
End Sub 
 
Private Sub TableModel_QueryColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs) 
    If (Not pivotSchemaChanged) OrElse Me.pivotGridControl1.PivotSchemaDesigner Is Nothing Then 
        pivotSchemaChanged = False 
        Return 
    End If 
 
    If e.Index = 3 OrElse e.Index = 4 Then 
        e.Size = 140 
        e.Handled = True 
    End If 
End Sub 
 
Sample link:  PivotGridControl 
 
Regards, 
Mohanraj G. 
 
 
  
 



MH Matthijs Huisman February 22, 2017 08:25 AM UTC

Thank you for your suggestion, it certainly helps to better understand how the events are linked.

Unfortunately an error occurs when I add: AddHandler Me.pivotGridControl1.PivotSchemaDesigner.SchemaChanged, AddressOf PivotSchemaDesigner_SchemaChanged when the ShowPivotFieldTableList is FALSE. The handler seems only to work with the PivotTableFieldList visible -> but it is no problem to wire and unwire this eventhandler....

But I am fine with how it works now!

BTW: I added the ResizeToFit command to the PivotSchemaDesigner.SchemaChanged event (and not like I wrote to the PivotRows.CollectionChanged handler -> I should not post stuff when I am in a hurry :( )

Thanks for your help!


MG Mohanraj Gunasekaran Syncfusion Team February 23, 2017 05:15 AM UTC

Hi Matthijs, 
 
Thanks for your update. 
 
We are glad to know that your reported problem has resolved.  
 
Please let us know if you have any further assistance on this. 
 
Regards, 
Mohanraj G. 


Loader.
Live Chat Icon For mobile
Up arrow icon