Hello team,
I am using Aspose.cells 7.0.2 for .NET. I am having a page filter in a pivot table and want to hide few values from the selection i.e. I want to unselect few values in the filter. In order to do this, I can use the HideItems function by using the appropriate index. However, I don’t know the index of the item, as the data is dynamic. Hence, I wanted to know if we can iterate through the items in a pivotfieldcollection.
I am doing the following:
PivotFieldCollection pvt_field = pivotTable.PageFields;
pvt_field[0].IsMultipleItemSelectionAllowed = true;
pvt_field[0].HideItem(0, true);
But I want to iterate through pvt_field[0].Items. I tried using a foreach statement, but it keeps erroring out. something like this:
foreach (PivotItem pvt in pvt_field[0].Items) { }
Could you please let me know how to do it? I want to check whether the pvt_fields[0].Items value is equal to some variable. If yes, hide it.
I also want to the same in a column filter.
Thanks in advance
Hi,
We think you may use this sample code:
e.g
PivotItem item = pvt_field[0].PivotItems["itemname"];
//or use "for" statement like this:
for (int i = 0; i < items.Count; i++)
{
}
Thank you.
Hi,
I tried the sample code but it looks like it would not work.
You have used a pivotitem ‘Item’ but are using items.count. May I know what is ‘item’?
Could you please let me know how to get the various values of the Pagefield?
Thanks,
Hi,
Could you please let me know what is the “itemname”?
Thanks,
Hi,
Thanks. I fixed the issue.
I used the following code:
PivotFieldCollection pvt_field = pivotTable9.PageFields;
pvt_field[0].IsMultipleItemSelectionAllowed = true;
for(int j=0; j<pvt_field[0].ItemCount;j++)
{
if (pvt_field[0].Items[j].Equals(“1-Outstanding”) || pvt_field[0].Items[j].Equals(“2-Highly Effective”) || pvt_field[0].Items[j].Equals("(blank)"))
{
pvt_field[0].HideItem(j, true);
}
}
Thanks for all your help!
Hi,
Thanks for your feedback and sample code.
It’s good to know that your issue is now resolved.
If you face any other issue, please feel free to post, we will be glad to assist you further.