Pivot Grid Control selection event

Good morning,
I'm working with pivot grid control and I need to handle SelectionChanged event after single cell's selection.

The event is succesfully raised but i cannot recover current info.

The RangeSelected property of the GridSelectionChangedEventArgs has width and height to 1 but is always empty.

Is it possible to recover row header and column header of the current cell, right? 


Thanks

Best regards,
Federico


1 Reply

SU Suriya Syncfusion Team October 19, 2018 09:01 AM UTC

Hi Federico, 

Yes. It is possible to recover the row header and column header of clicked cells with the help of PivotGridSelectionChangedEventArgs argument. 

Please refer to the code example below to achieve this: 
Form1.cs 
 
                 /// <summary> 
        /// Grid Settings for better look and feel 
        /// </summary> 
        private void InitializePivotGrid() 
        { 
            // Adding ItemSource to the Control 
            this.pivotGridControl1.ItemSource = ProductSalesData.GetSalesData(); 
 
            // Adding PivotRows to the Control 
            this.pivotGridControl1.PivotRows.Add(new PivotItem { FieldMappingName = "Product", TotalHeader = "Total" }); 
 
            this.pivotGridControl1.PivotRows.Add(new PivotItem { FieldMappingName = "Date", TotalHeader = "Total" }); 
 
            // Adding PivotColumns to the Control 
            this.pivotGridControl1.PivotColumns.Add(new PivotItem { FieldMappingName = "Country", TotalHeader = "Total" }); 
 
            this.pivotGridControl1.PivotColumns.Add(new PivotItem { FieldMappingName = "State", TotalHeader = "Total" }); 
 
            // Adding PivotCalculations to the Control 
            this.pivotGridControl1.PivotCalculations.Add(new PivotComputationInfo { FieldName = "Amount", Format = "$ #,##0.00", SummaryType = SummaryType.DoubleTotalSum }); 
 
            this.pivotGridControl1.PivotCalculations.Add(new PivotComputationInfo { FieldName = "Quantity", Format = "#,##0" }); 
 
            this.pivotGridControl1.TableControl.SelectionChanged += TableControl_SelectionChanged; 
 
            //tab key navigation set as false to move the next control 
            this.pivotGridControl1.TableControl.WantTabKey = false; 
            this.pivotGridControl1.TableModel.Options.AllowSelection = GridSelectionFlags.Any; 
        } 
 
        /// <summary> 
        /// Occurs when cell selection gets changed. 
        /// </summary> 
        /// <param name="sender">The source of the event.</param> 
        /// <param name="e">The <see cref="Syncfusion.Windows.Forms.PivotAnalysis.PivotGridSelectionChangedEventArgs"/> that contains the event data.</param> 
        private void TableControl_SelectionChanged(object sender, PivotGridSelectionChangedEventArgs e) 
        { 
            if (listBox1.Items.Count > 0) 
                listBox1.Items.Clear(); 
            if (e.SelectedItems != null) 
            { 
                for (int i = 0; i < e.SelectedItems.Count; i++) 
                { 
                    listBox1.Items.Add(e.SelectedItems[i].ToString()); 
                } 
            } 
        } 

The below link has, a working sample, screenshots and video to illustrate the above code snippet for your reference: 
 
Regards, 
Suriya 


Loader.
Up arrow icon