How to capture the index of the current cell with Excel like Selection Frame


Hello, I am currently working with a gridGrouping in winforms and I need in a selection event to capture the index and the selected value to calculate it just as excel does in its spreadsheet obtaining sum, average and count.

1 Reply 1 reply marked as answer

BT Balamurugan Thirumalaikumar Syncfusion Team January 25, 2021 12:58 PM UTC

Hi Oskar, 
Thanks for your using in Syncfusion products 
## How to capture the index of the current cell 
We have checked your query “How to capture the index of the current cell”. We suggest you to get the current cell value and index on TableControlCurrentCellMoved event is by getting the style of the current cell using GetTableViewStyleInfo() method by passing the RowIndex and ColumnIndex of the clicked cell.  
Code snippet C#:  
//Event Subscription 
            this.gridGroupingControl1.TableControlCurrentCellMoved += GridGroupingControl1_TableControlCurrentCellMoved;

//Event Customization
 
        private void GridGroupingControl1_TableControlCurrentCellMoved(object sender,GridTableControlCurrentCellMovedEventArgs e) 
        { 
            int rowIndex = e.TableControl.CurrentCell.RowIndex; 
            int colIndex = e.TableControl.CurrentCell.ColIndex; 
            MessageBox.Show("rowIndex = "+ rowIndex+"\n"+"colIndex = "+colIndex+"\n"+ 
                GetRecordValue(rowIndex, colIndex)); 
        }

//To Get the cell value of current record 
        private string GetRecordValue(int rowIndex, int columnIndex) 
        { 
            string cellValue = string.Empty; 
            //To get the style of current cell 
            GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, columnIndex); 
            if (style.TableCellIdentity != null && (style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell 
                || style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)) 
            { 
                Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
                //To get the cell value of current cell 
                cellValue = record.GetValue(style.TableCellIdentity.Column.Name).ToString(); 
            } 
            return cellValue; 
        } 
We have attached the sample for your reference and you can download the same from the following link
Sample link - https://www.syncfusion.com/downloads/support/directtrac/general/ze/GGC_SelectionCell679218396.zip 
## with Excel like Selection Frame 
We have provided a UG document for Excel like selection frame in Gridgrouping control. 
Balamurugan Thirumalaikumar. 


Marked as answer
Loader.
Up arrow icon