Hi
How can the pivot grid auto resize the width of it's columns according to the width of it's column's data.
PivotGridElement.BestFitHelper.BestFitColumns() doesn't work for me.
Basically I want to execute the best fit function (provided in context menu for any column) for all members of ColumnGroupDescriptions and RowGroupDescriptions.
Additionally, I want to hide the PivotRowDescriptorContainer, PivotFilterDescriptorContainer and PivotColumnDescriptorContainer when the pivotgrid has no data,
or remove the "Drag data items here", "Drag row items here" and "Drag column items here" message that is displayed in this case so that the user doesn't try to do so (I am not using the RadPivotFieldList).
5 Answers, 1 is accepted
Thank you for writing.
The BestFitColumns method is working with column group descriptions. If you want to also best fit the row headers you can use the BestFitRowHeaders method and pass the levels for each of row group elements:
foreach
(RadElement element
in
this
.radPivotGrid1.PivotGridElement.RowDescriptorsArea.Children)
{
PivotGroupDescriptorElement group = element
as
PivotGroupDescriptorElement;
if
(group ==
null
)
{
continue
;
}
this
.radPivotGrid1.PivotGridElement.BestFitHelper.BestFitRowHeaders(group.Level);
}
this
.radPivotGrid1.PivotGridElement.BestFitHelper.BestFitColumns();
Regarding your other question, I can suggest using a custom localization provider returning an empty string for the messages which need to be empty:
class
MyEnglishPivotGridLoclizationProvider : PivotGridLocalizationProvider
{
public
override
string
GetLocalizedString(
string
id)
{
switch
(id)
{
case
PivotStringId.DragDataItemsHere:
return
""
;
case
PivotStringId.DragColumnItemsHere:
return
""
;
case
PivotStringId.DragItemsHere:
return
""
;
case
PivotStringId.DragFilterItemsHere:
return
""
;
case
PivotStringId.DragRowItemsHere:
return
""
;
}
return
base
.GetLocalizedString(id);
}
}
This documentation article demonstrates how the localization provider can be instantiated and used in the pivot control: https://docs.telerik.com/devtools/winforms/pivotgrid/localization/localization.
Should you have further questions please do not hesitate to write back.
Regards,
Hristo
Progress Telerik
Hi Hristo
The code for BestFit operation works if executed on UpdateCompleted event, but does not work if executed immediately after setting the LocalDataSourceProvider.
Thanks for your help.
Yes, indeed. You will need to call this the best-fit logic once the control has updated and the row and column descriptions have been applied.
Let me know if you have other questions.
Regards,
Hristo
Progress Telerik
Hi Hristo
The code to best fit rows and columns works correctly if the pivotgrid is visible, but it sets incorrect width if the grid is not visible on the UI.
The best-fit helper as perquisite assumes that the layout has been passed. If your control is not visible you can trigger a layout update before calling the logic for best fitting the columns using the RadControl.LoadElementTree method:
this
.radPivotGrid1.LoadElementTree();
//...
this
.radPivotGrid1.PivotGridElement.BestFitHelper.BestFitColumns();
this
.radPivotGrid1.Visible =
true
;
Let me know if you have other questions.
Regards,
Hristo
Progress Telerik