I have a key mapping to expand the selected row. I would like it to function on all selected rows. Is it possible?
// Add a custom key/ction mapping to the grid to expand the current row. theGrid.KeyActionMappings.Add(new GridKeyActionMapping(Keys.Down, UltraGridAction.ExpandRow, 0, UltraGridState.RowExpandable, 0, SpecialKeys.ShiftCtrl, true));
Hi Kipp,
Since there's no UltraGridAction for "ExpandAllSelectedRows", KeyActionMappings probably isn't a good way to handle this. I'd just handle the grid's KeyDown event and watch for the Down arrow, then loop through the Selected Rows and Expand each one. Be sure to set e.Handled to true inside the event so that the grid doesn't process the key.
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { var grid = (UltraGrid)sender; if (e.KeyCode == Keys.Down) { e.Handled = true; foreach (var row in grid.Selected.Rows) { row.Expanded = true; } } }
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { var grid = (UltraGrid)sender; if (e.KeyCode == Keys.Down) { e.Handled = true;
foreach (var row in grid.Selected.Rows) { row.Expanded = true; } } }
private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
{
var grid = (UltraGrid)sender;
if (e.KeyCode == Keys.Down)
e.Handled = true;
foreach (var row in grid.Selected.Rows)
row.Expanded = true;
}
Thanks Mike.
I wanted to make sure there wasn't some way to link in some custom action.
I'm curious. You suggested using Key-Down. I would think Key-Up would be a better choice. Do you have any thoughts on this?
Great help! Exactly why I asked!
The problem with KeyUp is that it happens after KeyDown and KeyPress. So if the grid already has some functionality that respond to KeyDown or KeyPress, then your KeyUp code may get hit after that, or it may not get hit at all.
That may or may not be desirable in this case. It depends on the behavior you want and what other functionality in the grid might interfere with the down arrow. KeyDown essentially gives you first crack at the key. So if you discover that the down arrow is not working in some case where you want it to do something other than expand rows, you could put code into KeyDown to check for that case and not cancel the event. On the other hand, if you use KeyUp, then the grid will try to process the Down arrow before you can get it and you will only get a KeyUp either after the grid has already processed it or not at all.
If you do decide to use KeyUp, you will probably want to check e.Handled and not do anything if it's true. Since that indicates that the grid already did something with the down arrow.