Hi. I am trying to code in a bunch of excel shortcuts in the ultrawingrid.
I need to implement the below:
CellClickAction needs to remain "CellSelect"
F2 gets you into Edit mode, so should any alphanumeric entry. And once you are in there, you should be able to use the arrow keys to move Left, right, top or bottom.
I am implementing the below in my Keydown event:
//Enter edit mode on any alphanumeric input if( (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || (e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9) || (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 ) ) { if (grdMain.UltraGrid.ActiveCell != null && grdMain.UltraGrid.ActiveCell.IsDataCell) { grdMain.UltraGrid.PerformAction(UltraGridAction.EnterEditMode); e.SuppressKeyPress = false; } }
if (e.KeyCode == Keys.Left) { grdMain.UltraGrid.PerformAction(UltraGridAction.PrevCell); } if (e.KeyCode == Keys.Right) { grdMain.UltraGrid.PerformAction(UltraGridAction.NextCell); } if (e.KeyCode == Keys.Up) { grdMain.UltraGrid.PerformAction(UltraGridAction.AboveCell); } if (e.KeyCode == Keys.Down) { grdMain.UltraGrid.PerformAction(UltraGridAction.BelowCell); }The 2 problems i am facing are:1) It enters edit mode, but loses the first character input2) The arrow keys are somehow jumping alternate cells and not to the next cellAlso, i need to stop the wrap around from the last cell to the first cell(same row or the next). So if i press --> on the last cell, it should stay there.Please advise.
Hi,
First, let's talk about the arrow keys... if the grid is jumping two cells instead of one, then my guess is that the PerformAction is performed, which leaves the grid in a state where it has a selected cell, and then the key gets processed by the grid, which moves it one more cell. So you probably just need to set e.Handled to true when you call PerformAction in response to an arrow key.
You might also want to take a look at this KB article.
HOWTO:UltraWinGrid Cursor Movement like Excel
Regarding the alphanumeric keys, this is much more difficult. When you type a key and a cell is not in edit mode, the grid handles the keystroke. Your code then puts the cell into edit mode. But whether you mark the key handled or not, it will never get placed into the cell because when the cell enters edit mode (assuming it's a normal text cell, not a masked cell), the grid displays a child TextBox control in that cell. The keystroke never goes to that TextBox control.
So there are a couple of things you could try, but it could be tricky because of timing.
What I would do is try to get a reference to the TextBox. You could use grid.Controls[0] after calling PerformAction. Then you could use SendKeys to send a keystroke to the TextBox, or just set it's Text to whatever you want.
My guess is that this will not work, either because the TextBox isn't there, yet (it might not get shown until the next time the grid paints), or the grid might overwrite the text after you set it.
If that's the case, then try calling PerformAction first, then use a BeginInvoke to call a method which sends the key or sets the Text. The invoke should create enough of a delay so that the TextBox is there and the grid is done with it.