Hi Telerik Folks,
We've overridden our "ProcessKey(KeyEventArgs keys) in a customized BaseGridBehavior class that we're using. In doing this, the default keys for selecting a block of cells (Shift + the arrow keys) are no longer working.
To overcome this we're trying to put in custom code to explicitly do the same thing. It looks like this...
...It works, pretty much but it's performance gets exponentially slower the larger the block of cells that is selected holding down the Shift key. It does this most likely because it loops through every cell and individually selects and flips the "IsSelected" property.
Is there a more efficient way to select blocks of cells, like using the GridNavigator.BeginSelection? Is there a sample for using the GridNavigationContext parameter to do it this way given two cell addresses?
Are we going about this the wrong way? Is there a more efficient way to make it opt out of our ProcessKey override and have it use the default behavior?
Thanks for any help you can provide...
We've overridden our "ProcessKey(KeyEventArgs keys) in a customized BaseGridBehavior class that we're using. In doing this, the default keys for selecting a block of cells (Shift + the arrow keys) are no longer working.
To overcome this we're trying to put in custom code to explicitly do the same thing. It looks like this...
01.
public
class
MyGridBehavior : BaseGridBehavior
02.
{
03.
04.
05.
public
void
SelectCellBlock(GridViewCellInfo SelectedCellTopLeft,GridViewCellInfo SelectedNewCell)
06.
{
07.
this
.GridControl.ClearSelection();
08.
09.
10.
int
TopRowIndex = SelectedCellTopLeft.RowInfo.Index <= SelectedNewCell.RowInfo.Index ? SelectedCellTopLeft.RowInfo.Index : SelectedNewCell.RowInfo.Index;
11.
int
BottomRowIndex = SelectedCellTopLeft.RowInfo.Index >= SelectedNewCell.RowInfo.Index ? SelectedCellTopLeft.RowInfo.Index : SelectedNewCell.RowInfo.Index;
12.
13.
int
LeftColumnIndex = SelectedCellTopLeft.ColumnInfo.Index <= SelectedNewCell.ColumnInfo.Index ? SelectedCellTopLeft.ColumnInfo.Index : SelectedNewCell.ColumnInfo.Index;
14.
int
RightColumnIndex = SelectedCellTopLeft.ColumnInfo.Index >= SelectedNewCell.ColumnInfo.Index ? SelectedCellTopLeft.ColumnInfo.Index : SelectedNewCell.ColumnInfo.Index;
15.
16.
//this.GridControl.GridNavigator.BeginSelection(new GridNavigationContext() { InputType = InputType.Keyboard, ModifierKeys = Keys.Shift });
17.
18.
for
(
int
rowIndex = TopRowIndex; rowIndex <= BottomRowIndex; rowIndex++)
19.
{
20.
for
(
int
columnIndex = LeftColumnIndex; columnIndex <= RightColumnIndex; columnIndex++)
21.
{
22.
this
.GridControl.Rows[rowIndex].Cells[columnIndex].IsSelected =
true
;
23.
}
24.
}
25.
}
26.
27.
public
override
bool
ProcessKey(KeyEventArgs keys)
28.
{
29.
30.
if
(keys.Shift && keys.KeyCode ==Keys.Down)
31.
{
32.
GridViewCellInfo SelectedCellTopLeft =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
33.
this
.GridControl.GridNavigator.SelectNextRow(1);
34.
GridViewCellInfo SelectedNewCell =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
35.
SelectCellBlock(SelectedCellTopLeft, SelectedNewCell);
36.
return
false
;
37.
38.
}
39.
40.
if
(keys.Shift && keys.KeyCode == Keys.Up)
41.
{
42.
GridViewCellInfo SelectedCellTopLeft =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
43.
this
.GridControl.GridNavigator.SelectPreviousRow(1);
44.
GridViewCellInfo SelectedNewCell =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
45.
SelectCellBlock(SelectedCellTopLeft, SelectedNewCell);
46.
return
false
;
47.
48.
}
49.
50.
if
(keys.Shift && keys.KeyCode == Keys.Left)
51.
{
52.
GridViewCellInfo SelectedCellTopLeft =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
53.
this
.GridControl.GridNavigator.SelectPreviousColumn();
54.
GridViewCellInfo SelectedNewCell =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
55.
SelectCellBlock(SelectedCellTopLeft, SelectedNewCell);
56.
return
false
;
57.
}
58.
59.
if
(keys.Shift && keys.KeyCode == Keys.Right)
60.
{
61.
GridViewCellInfo SelectedCellTopLeft =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
62.
this
.GridControl.GridNavigator.SelectNextColumn();
63.
GridViewCellInfo SelectedNewCell =
this
.GridControl.SelectedCells.OrderBy(r => r.RowInfo.Index).ThenBy(c => c.ColumnInfo.Index).FirstOrDefault();
64.
SelectCellBlock(SelectedCellTopLeft, SelectedNewCell);
65.
return
false
;
66.
}
67.
}
68.
}
...It works, pretty much but it's performance gets exponentially slower the larger the block of cells that is selected holding down the Shift key. It does this most likely because it loops through every cell and individually selects and flips the "IsSelected" property.
Is there a more efficient way to select blocks of cells, like using the GridNavigator.BeginSelection? Is there a sample for using the GridNavigationContext parameter to do it this way given two cell addresses?
Are we going about this the wrong way? Is there a more efficient way to make it opt out of our ProcessKey override and have it use the default behavior?
Thanks for any help you can provide...