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

Cell click event handler

I have a problem with the events while cliking in a cell. I use the first cell of a row to apply an action to all the selected cells in this row. I use something like this (C# code) : SuspendChangeEvents(); if ( col == 0 && row == 4 && Selections.Ranges.Count > 0 ) { BeginUpdate(); SortedList toDelete = new SortedList(); for ( int i = 0; i < Selections.Ranges.Count; i++ ) { GridRangeInfo range = Selections.Ranges[i]; for ( int j = range.Left; j <= range.Right; j++ ){ toDelete.Add( j, j );}} for ( int i = 1; i <= toDelete.Count; i++ ){ int j = (int)toDelete.GetByIndex( toDelete.Count - i ); DeleteSequence( j ); // some personal stuff GridRangeInfo range = GridRangeInfo.Cols( j - 1, j - 1 ); Selections.Remove( range ); if ( ColumnDeleted != null ){ // Fire personal event TableEventArgs args = new TableEventArgs( j, ws ); ColumnDeleted( this, args );}} Selections.Clear(); EndUpdate( true ); Refresh(); ResumeChangeEvents(); First, I have to set the CellValue property for the cell I clicked each time the handler is called, or else the text simply dissapears (not mentionned in the sample code above). Moreover, sometimes after calling this handler, the next click anywhere on the grid will reenter the handler. I just don't know why. Is this due to the events I fire from the handler method ? I can't figure what happens. Hope my explacations will be clear ;o) Thank you.

1 Reply

AD Administrator Syncfusion Team November 6, 2002 05:51 AM UTC

> I have a problem with the events while cliking in a cell. I use the first cell of a row to apply an action to all the selected cells in this row. > > I use something like this (C# code) : > > SuspendChangeEvents(); > if ( col == 0 && row == 4 && Selections.Ranges.Count > 0 ) { > BeginUpdate(); > SortedList toDelete = new SortedList(); > for ( int i = 0; i < Selections.Ranges.Count; i++ ) { > GridRangeInfo range = Selections.Ranges[i]; > for ( int j = range.Left; j <= range.Right; j++ ){ > toDelete.Add( j, j );}} > > for ( int i = 1; i <= toDelete.Count; i++ ){ > int j = (int)toDelete.GetByIndex( toDelete.Count - i ); > DeleteSequence( j ); // some personal stuff > GridRangeInfo range = GridRangeInfo.Cols( j - 1, j - 1 ); > Selections.Remove( range ); > if ( ColumnDeleted != null ){ > // Fire personal event > TableEventArgs args = new TableEventArgs( j, ws ); > ColumnDeleted( this, args );}} > Selections.Clear(); > EndUpdate( true ); > Refresh(); > ResumeChangeEvents(); > > First, I have to set the CellValue property for the cell I clicked each time the handler is called, or else the text simply dissapears (not mentionned in the sample code above). > Moreover, sometimes after calling this handler, the next click anywhere on the grid will reenter the handler. I just don't know why. Is this due to the events I fire from the handler method ? I can't figure what happens. > Hope my explacations will be clear ;o) > Thank you. The default behavior is for a cell to begin editing when you click on it. This is controlled on a grid-wide basis by the grid's ActivateCurrentCellBehavior property. So, when you click, the cell goes in the edit mode, and the passes the focus to the control determined by the CellType of that cell, probably a TextBox unless you have set it to something else. I suspect the problems are coming about becuase of this active cell. If you do not want your user's to edit this column, you could try setting the CellType to Static (from the default TextBox) to see if that would avoid this behavior. Another thing you could try is to call CurrentCell.EndEdit() at the start of your code to see if that would take care of the problem.

Loader.
Live Chat Icon For mobile
Up arrow icon