Hi,
when there is no row selected in the grid, and the user presses HOME or END, the Grid fails with Index out of bounds exception.
There is a problem in procedure TNxCustomGrid.ProcessKeyDown(var Key: Word; Shift: TShiftState), because it expects that a row is selected to calculate grid movement.
Please fix this.
Thanks & Regards,
Jan
Index out of bounds - bug in ProcessKeyDown
Started by czbird, Oct 21 2014 01:01 PM
3 replies to this topic
#1
Posted 21 October 2014 - 01:01 PM
#2
Posted 21 October 2014 - 01:07 PM
Meanwhile, I have incorporated this workaround in my project (onkeydown event):
if (Key in [VK_HOME, VK_END]) and (Grid.SelectedCount = 0) and (Grid.RowCount > 0) then
Grid.SelectCell(0, Grid.FirstVisibleRow);
if (Key in [VK_HOME, VK_END]) and (Grid.SelectedCount = 0) and (Grid.RowCount > 0) then
Grid.SelectCell(0, Grid.FirstVisibleRow);
#3
Posted 23 October 2014 - 10:16 AM
Hi,
I will fix it. Thank you for code sample.
I will fix it. Thank you for code sample.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
#4
Posted 23 October 2014 - 10:31 AM
Hi,
Please tell me how this update works:
Please tell me how this update works:
procedure TNxCustomGrid.ProcessKeyDown(var Key: Word; Shift: TShiftState); var Delta: Integer; begin if goDisableKeys in Options then Exit; if (gtEdit in GridState) or (gtInput in GridState) then begin case Key of VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_HOME, VK_END: Exit; end; end; case Key of 65: if (ssCtrl in Shift) then SelectAll; VK_TAB: if (ssShift in Shift) then MoveToPrevCell(True) else MoveToNextCell(True); VK_LEFT: begin if InputSelected or not(goSelectFullRow in Options) or (aoIndicateSelectedCell in AppearanceOptions) then MoveSelectionLeft(mkArrows) else HorzScrollBar.Prior; end; VK_RIGHT: begin if InputSelected or not(goSelectFullRow in Options) or (aoIndicateSelectedCell in AppearanceOptions) then MoveSelectionRight(mkArrows) else HorzScrollBar.Next; end; VK_UP: MoveSelectionUp(Shift); VK_DOWN: MoveSelectionDown(Shift); VK_HOME: begin if RowCount > 0 then begin SelectRows(Shift, 0, IfThen(SelectedRow > -1, SelectedRow, LastVisibleRow)); case HomeEndBehaviour of hebTopBottom: if FColumns.Exists(SelectedColumn) then SelectFirstRow(Shift); hebLeftRight: SelectFirstColumn; end; end; end; VK_END: begin if RowCount > 0 then begin SelectRows(Shift, IfThen(SelectedRow > -1, SelectedRow, FirstVisibleRow), RowCount - 1); case HomeEndBehaviour of hebTopBottom: if FColumns.Exists(SelectedColumn) then SelectLastRow(Shift); hebLeftRight: SelectLastColumn; end; end; end; VK_PRIOR: if not VertScrollBar.IsFirst then begin Delta := GetVisibleCount; { n rows are shown in view } if SelectedRow > FFirstRow then SelectedRow := FFirstRow else begin { Bn: First row in view is selected } MoveSelectionBy(-Delta); { move for n visible rows } ScrollToRow(SelectedRow); end; end else SelectFirstRow; VK_NEXT: if not VertScrollBar.IsLast then begin Delta := GetVisibleCount; { n rows are shown in view } if SelectedRow < Pred(FFirstRow + Delta) then begin { Bn: Real index of last row in view } SelectedRow := GetLastRowInView(Delta); end else begin if SelectedRow + Delta > RowCount then begin SelectLastRow; Exit; end; { Bn: Last row in view is selected } MoveSelectionBy(Delta); ScrollToRow(SelectedRow); end; end; end; { case } end;
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users