Example #1
0
        void worksheet_BeforeCellKeyDown(object sender, Events.BeforeCellKeyDownEventArgs e)
        {
            // we just customize the key process if checkbox is enabled
            if (chkLimitSelection.Checked)
            {
                // redefine Tab key to switch between different input block
                if (chkTabToNextBlock.Checked &&
                    (e.KeyCode | KeyCode.Tab) == KeyCode.Tab)
                {
                    int index = this.validRanges.FindIndex(vr => new RangePosition(vr).Contains(e.CellPosition));

                    index++;
                    if (index >= this.validRanges.Count)
                    {
                        index = 0;
                    }

                    this.worksheet.SelectionRange = new RangePosition(validRanges[index]);
                }
                else
                {
                    // Check the start and end position of the new selection range
                    // Abort operations if any selection position not be included in the list defined above
                    e.IsCancelled = !validRanges.Any(vr => new RangePosition(vr).Contains(e.CellPosition));
                }
            }
        }
Example #2
0
        void worksheet_BeforeCellKeyDown(object sender, Events.BeforeCellKeyDownEventArgs e)
        {
            // 選択範囲を制御する場合
            if (chkLimitSelection.Checked)
            {
                // Tabキーが押された場合の処理
                if (chkTabToNextBlock.Checked &&
                    (e.KeyCode | KeyCode.Tab) == KeyCode.Tab)
                {
                    int index = this.validRanges.FindIndex(vr => new RangePosition(vr).Contains(e.CellPosition));

                    index++;
                    if (index >= this.validRanges.Count)
                    {
                        index = 0;
                    }

                    this.worksheet.SelectionRange = new RangePosition(validRanges[index]);
                }
                // Tab以外のキーが押された場合の処理(例えば選択範囲の移動)
                else
                {
                    // 選択範囲が変更された場合、選択可能な範囲に囲まれるかどうかをチェックする
                    // 選択可能な範囲からはみ出る場合、IsCancelledプロパティをtrueに設定して選択操作を禁止
                    e.IsCancelled = !validRanges.Any(vr => new RangePosition(vr).Contains(e.CellPosition));
                }
            }
        }