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
close icon

SelectedItems in pivot control is always null

Hello, I'm trying to generate some charts from selected cells in a pivot control. I set AllowSelection = true but when I try to get selected cells from pivotGrid1.SelectedItems I'm always getting null. Same happens with pivotGrid1.SelectedCell although I guess the latter does not apply on multiple selection. Is that the correct way of accessing selected cells?
Thanks in advance.

4 Replies

AA Arulraj A Syncfusion Team March 6, 2019 11:55 AM UTC

Hi Carlos, 

Thanks for using Syncfusion product. 

We are unable to reproduce the reported issue “SelectedItems value is null while selecting the cells in pivot grid”. Based on the cell selection values in pivot grid, the selected item values are correctly displayed in the listbox. Also, We cannot see any null values while selecting the cells in pivot grid control. 

Please refer the attached videos and sample from the following location: 

Also, refer our UG documentation from the  following link: 

Could you please share your working sample or modify the attached sample in order to reproduce the reported issue, so that it could be helpful to proceed further. 

Regards, 
Arulraj A 



CF Carlos Fernando Consigli March 6, 2019 12:27 PM UTC

Hi Arulraj. Thanks for your quick answer. Maybe I'm not using this property as it is supposed to. I'm trying to access the SelectedItems from code behind. I'm attaching a sample showing something similar to what I'm trying to do and how in that case I get null values.
Greetings

Attachment: SampleSelectedItems_e4537553.zip


CF Carlos Fernando Consigli March 6, 2019 06:42 PM UTC

Ok, I figured it out and solved it. I don't know if this is intended or it's a bug, but I solved it by just binding an empty handler to SelectionChanged. Now SelectedItems is not null any more when I access it from code behind.

....
pivotGrid.SelectionChanged += PivotGrid_SelectionChanged;
.....

private void PivotGrid_SelectionChanged(object sender, PivotGridSelectionChangedEventArgs e)
{     
}

Again, maybe this is a design decision based on performance ("Why update SelectedItems collection if there is no handler bound to SelectionChanged event?") or it maybe is indeed a minor bug.
Thanks again for your quick support.




AA Arulraj A Syncfusion Team March 7, 2019 06:47 AM UTC

Hi Carlos, 

Thanks for the update. 

The reported behavior is the default behavior of pivot grid and it is not a bug. The SelectedItems property values are assigned while triggering the SelectionChanged event handler only. Otherwise, you’ll get the null values in the SelectedItems property. Using the event handler, you’ll get the SelectedItems and then you can render the chart in your application based on the selected items. 

Please refer the below code sample: 

#MainWindow.xaml.cs 
 
        private object selectedItem; 
        public MainWindow() 
        { 
            InitializeComponent(); 
            pivotGrid1.SelectionChanged += PivotGrid1_SelectionChanged; 
        } 
 
        private void PivotGrid1_SelectionChanged(object sender, Syncfusion.Windows.Controls.PivotGrid.PivotGridSelectionChangedEventArgs e) 
        { 
            selectedItem = e.SelectedItems; 
        } 
 

Please find the modified sample from the following location: 

Please let us know if you need any further assistance. 

Arulraj A 


Loader.
Live Chat Icon For mobile
Up arrow icon