Issue with CellKeyPressed event


#1

Greetings,

I've been working on code to handle when a user selects a cell and then uses the shift/arrow keys to select a range of cells. In the CellKeyPressed event handler in my form, when I do a griddesktop.GetActiveWorksheet().GetLastSelection(), the selected range is from before the shift/arrow key was pressed.

ie Cell A1 has focus. I press shift/Right Arrow. The CellKeyPressed event fires and I call GetLastSelection in the handler. The cellrange returned by GetLastSelection is A1:A1, rather than A1:B1 as I would expect. The control state shows that A1:B1 has been selected.

I'm assuming that the CellKeyPressed event fires before the GetLastSelection state is updated. Is this the expected behavior?

Thanks,

Chris Powell


#2

Hi Chris,

I added a "SelectedCellRangeChanged" event in the control, you can handle this event like this:

private void gridDesktop1_SelectedCellRangeChanged(object sender, Aspose.Grid.Desktop.CellRangeEventArgs e)
{
this.Text = e.CellRange.ToString();
}

You can invoke GetLastSelection() in this event handler too.

The CellKeyPressed event arguments has a property of "Handled", if you set the property true, the control will stop process the key. You can prevent user from inputting some command like "Control + C" etc.

Please try the version 1.7.1.2 in attachment. And in this version, "click start cell then shift and/or ctrl click end cell" is supported.

Thanks


#3

Greetings,

I've modified my code to use the SelectedCellRangeChanged event. Everything appears to be working correctly. If I encounter any issues with it, I'll let you know.

Thanks,

Chris Powell