I'm using ultragrid KeyDown to implement navigation of the grid using the arrow keys. This works great, however I also use AfterCellUpdate to update the XML used to populate the grid. The AfterCellUpdate action updates the XML and reloads it to the datatable used as the ultragrids datasource.
The problem is that if I change a value in a cell, when I push an arrow key to move to another cell, the AfterCellUpdate actions take over and the next cell is not selected.
What's a good strategy to implement navigation with arrow keys along with being able to update values when they are changed?
Hello Clint,
Thank you for posting to Infragistics Community!
I have been looking into your question and based on your description I assume that the custom navigation affects cell in edit mode, is this correct? In an effort to reproduce a similar setup, I prepared a small sample with an UltraGrid having its KeyDown event handled to allow navigating between cells with the arrow keys. Additionally, there is a handler for the AfterCellUpdate event for demonstration purposes.
What I can say is that on my side, the fact that a cell value is updated does not hinder the custom navigation.
It is possible that something in your configuration is different and results in the observed behavior. In order to be able to assist you further, I would like to ask you to please, check the sample out and modify it with any relevant code and see if it is reproducible there as well. If it is, please, send it back to me so I can investigate it further and eventually come up with a workaround solution.
Looking forward to hearing from you.
Best regards, Bozhidara Pachilova Associate Software Developer
6523.UGKeyDownAndUpdate.zip
I see the issue now. In the AfterCell update, once the XML is written, I reload the data table used as the ultragrids datasource. When the table is reloaded, it looks like it refreshes the grid, which then moves me back to the first record.
If I remove the step to reload the datatable, everything works as expected, I can down arrow or up arrow and update the next cell.
Is there a way to maintain the position in the grid when that grids datasource is refreshed?
Hi Clint,
Thank you for your patience.
After further looking into your scenario, I determined that it would indeed be the case to keep the last active cell’s position in terms of row and field indexes instead of an UltraGridCell object, as it would be a different one when reassigning the data source. This I assume you have already implemented looking at the sample code. Additionally, I modified the previous sample to test a similar data source changing setup and my suggestion is to make sure the grid has exited edit mode before performing the other actions about activating the adjacent cells and entering edit mode for them. It appears that this allows the editing flow to carry on as expected and the grid continues in a correct state.
ultraGrid1.PerformAction(UltraGridAction.ExitEditMode);
In addition, by manually exiting edit mode before navigating, the AfterCellUpdate event is triggered just then, which allows for updating the value and then proceeding with navigating per the pressed arrow key after reactivating the current cell, the navigation flow is continued in the expected following direction.
Please, find the updated sample attached below and let me know if this is an accurate demonstration of what you’re trying to achieve.
7774.UGKeyDownAndUpdate2.zip
Thank you, this worked great for me. The exit edit mode was the key.
One final question. When I down arrow, it places the cursor at the end of the text. What command would have all text in the field selected?
My normal use case for this action is to either delete what's in the field or paste in text to replace what is there.
I am glad that the suggestion works for you.
To address your latest query, what I can say is that the grid has the cell’s editor text selected automatically when entering edit mode, which you could notice in the sample when the action is programmatically invoked with the EnterEditMode command. However, when the custom keydown navigation is executed, the arrow keys being pressed are still handled by the grid and result in deselecting the editor’s text. Thus, my suggestion is to mark the event as handled after performing the custom navigation, which will keep the text as selected. You could test this in the previous sample by simply adding the last line:
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { if (this.CheckArrowNavigationKeys(e.KeyCode)){ this.ultraGrid1.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.ExitEditMode); this.NavigatePerDirection(); this.ultraGrid1.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode); e.Handled = true; } }
Please, try this on your side and let me know if it helps.
Best regards, Bozhidara Pachilova
Works perfect, thanks again!
Glad to hear it works. Thank you for using Infragistics components!