In this application, generally the user starts with either a blank slate (for which no grid is present until the 'Add row' button is presssed to add a blank record, which they then fill in), or some amount of data that's either been loaded from a previous session or imported. Before, if you wanted to add 5 new rows, you have to hit the 'Add row' button (which actually alters the VM, not the view) five times.
The functionality I am looking for is that when you tab past the last column of the last record, rather than giving focus to the next UIElement in the view, it instead adds a new blank record at the end of the grid, and sets the first cell to edit mode. This allows a user to very quickly input lots of data by keyboard without having to move the mouse up to the 'add row' button for each new line.
I cannot simply make an event handler for the LostKeyboardFocus event, because there are quite a number of other situations in which that event would fire when unintended. Perhaps I need to handle the tab 'button down' event directly with lots of conditionals? I'm hoping there's a more elegant way.
Hello,
There are couple of ways you can achieve this. You can use the EditModeEnded/ing event and check if the Tab key has been pressed and the index of the edited cell/record and add a new record in the XDG's source. Another way would be to intercept the Executed(int)Command event and check the command (for example DataPresenterCommands.RecordNext, etc) and do the same.
Thanks, that worked nicely.
For posterity, I accomplished the desired functionality by creating a behavior within which the core is simply,
void AssociatedObject_ExecutingCommand(object sender, Infragistics.Windows.Controls.Events.ExecutingCommandEventArgs e) { if (e.Command.Name == "CellNextByTab" && (this.AssociatedObject.ActiveCell.Field.Index == this.AssociatedObject.ActiveCell.Field.Owner.Fields.Count - 1) && (this.AssociatedObject.ActiveCell.Record.Index == (this.AssociatedObject.ActiveCell.DataPresenter).Records.Count - 1) ) { //Fire add record command here } }
Note that I went with using 'CellNextByTab', as RecordNext isn't called when tabbing from the last record in our current setup.
Thanks again.