Articles in this section

How to maintain the customized column width of WinForms PivotGridControl after drag-and-drop operation?

Persist the resized column width values

You can customize the width of desired column in the WinForms PivotGrid by using the TableModel.Model.ColWidths property. To maintain the customized column width while dragging the pivot fields of pivot schema designer or group bar, the ColWidthsChanged event should be invoked, and you should define the width of required columns in the corresponding event handler method.


Refer to the following code sample to maintain the customized column width of the pivot grid while dragging in the pivot schema designer or group bar.


C#

public Form1()
{
    InitializeComponent();
    pivotGridControl1.ShowPivotTableFieldList = true;
    pivotGridControl1.ShowGroupBar = true;
    pivotGridControl1.TableModel.Model.ColWidths[1] = 110;
    pivotGridControl1.TableModel.Model.ColWidths[2] = 110;
    pivotGridControl1.TableControl.GroupDropArea.ColWidthsChanged += GroupDropArea_ColWidthsChanged;
}

private void GroupDropArea_ColWidthsChanged(object sender, GridRowColSizeChangedEventArgs e)
{
    pivotGridControl1.TableModel.Model.ColWidths[1] = 110;
    pivotGridControl1.TableModel.Model.ColWidths[2] = 110;
}

VB

Public Sub New()
    InitializeComponent()
    pivotGridControl1.ShowPivotTableFieldList = True
    pivotGridControl1.ShowGroupBar = True
    pivotGridControl1.TableModel.Model.ColWidths(1) = 110
    pivotGridControl1.TableModel.Model.ColWidths(2) = 110
    AddHandler pivotGridControl1.TableControl.GroupDropArea.ColWidthsChanged, AddressOf GroupDropArea_ColWidthsChanged
End Sub

Private Sub GroupDropArea_ColWidthsChanged(ByVal sender As Object, ByVal e As GridRowColSizeChangedEventArgs)
    pivotGridControl1.TableModel.Model.ColWidths(1) = 110
    pivotGridControl1.TableModel.Model.ColWidths(2) = 110
End Sub

PivotGrid with customized width for first two columns

   Pivot grid with customized width for first two columns

 

PivotGrid maintaining customized width for first two columns after drag and drop

   Pivot grid maintaining customized width for first two columns even after performing drag and drop in pivot schema designer


Conclusion

I hope you enjoyed learning about how to maintain the customized column width after drag-and-drop operation in PivotGrid.

You can refer to our WinForms PivotGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PivotGrid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied