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
Thanks so much,Shaolin
Hello Shaolin,
Thank you for your feedback.
Yes, you are correct. This will not work in this case. However, you can handle KeyDown event of the grid and add some custom logic to extend/shrink the selection, as MS Excel does, when Shift+Arrow key is pressed.
Please check the attached sample where I have implement this for you. Note, my sample is simple enough and showing how this could be done in nonhierarchical grid and does not scrolls the selection. For more complex scenarios you will need to add some additional logic. If you need help with this please contact our Consulting Team at services@infragistics.com.
After working on this and doing some research the idea to retain the active cell in the grid while selection changes was considered to be a new feature idea. You can post this idea at ideas.infragistics.com.
One more thing. If what you need in your application is to simulate the MS Excel, consider using our UltraSpreadSheet control.
Please 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
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.