Hi,
When I click a cell and drag the cursor to a different cell, a range of cells are selected. The active cell is always the set to the cell the cursor is moved to. For example, if I click the cell of the first row and the first column and drag the cursor to the cell of the third row and the third column, a range of nine cells are selected and the active cell is set to the cell of the third row and the third column. Is there a way to keep the active cell to the starting cell while the cursor is dragged, which is the cell of the first row and the first column in my example? This is the behavior of MS Excel and my users are used to it.
Thanks,Shaolin
Hi Shaolin,
You may achieve this behavior by handling BeforeSelectChange and AfterSelectChange events of the grid. In BeforeSelectChange event you have a reference to the new selection trough event arguments. You can check the new selection, and if it is containing only one cell save a reference to this cell in some private field. In AfterSelectChange event you will need to check if you have saved a reference to a cell in your private field. If so set the grid’s active cell to point to the cached value. You can use code like this:
private UltraGridCell activeCellCached = null;
private void UltraGrid1_BeforeSelectChange(object sender, BeforeSelectChangeEventArgs e){ // If the new selection is of cells get a reference to the first // selected cell and assign it to the cached active cell field if(e.NewSelections.Cells.Count == 1) { this.activeCellCached = this.ultraGrid1.ActiveCell; }} private void UltraGrid1_AfterSelectChange(object sender, AfterSelectChangeEventArgs e){ // If cashed active cell is not null set the grid active cell to // refer to this cached cell value if(this.activeCellCached != null) { this.ultraGrid1.ActiveCell = this.activeCellCached; }}
Please check the attached sample where I have implement this for you and let me know if you have any additional questions.
Hi Milko,
Thanks so much for your response!
There is an issue with this solution. The method disables extending selection by holding down SHIFT and pressing the arrow keys.
Thanks again,Shaolin