セル編集開始時のカーソル位置を変更したい

文書番号 : 38963     文書種別 : 使用方法     登録日 : 2015/07/02     最終更新日 : 2015/07/02
文書を印刷する
対象製品
SPREAD for Windows Forms 8.0J
詳細
セル型のFocusPositionプロパティにより、セルが編集状態になった時のカーソル位置を変更することができます。フォーカス位置は下記EditorFocusCursorPosition列挙体の中から指定します。

◎サンプルコード(VB)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  ' エディタのタイプまたは選択ポリシーによって決定(デフォルト)
  Dim txt_Inherit As New FarPoint.Win.Spread.CellType.TextCellType
  txt_Inherit.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.Inherit
  FpSpread1.Sheets(0).Cells(0, 0).CellType = txt_Inherit

  ' クリックした位置にカーソルを配置(Excelと同様の動作)
  Dim txt_MouseLocation As New FarPoint.Win.Spread.CellType.TextCellType
  txt_MouseLocation.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.MouseLocation
  FpSpread1.Sheets(0).Cells(0, 1).CellType = txt_MouseLocation

  ' 常に先頭にカーソルを配置
  Dim txt_FirstInputPosition As New FarPoint.Win.Spread.CellType.TextCellType
  txt_FirstInputPosition.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.FirstInputPosition
  FpSpread1.Sheets(0).Cells(0, 2).CellType = txt_FirstInputPosition

  ' 常に最後方にカーソルを配置
  Dim txt_End As New FarPoint.Win.Spread.CellType.TextCellType
  txt_End.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.End
  FpSpread1.Sheets(0).Cells(0, 3).CellType = txt_End

  ' 文字列を全選択状態にする
  Dim txt_SelectAll As New FarPoint.Win.Spread.CellType.TextCellType
  txt_SelectAll.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.SelectAll
  FpSpread1.Sheets(0).Cells(0, 4).CellType = txt_SelectAll

  FpSpread1.Sheets(0).SetValue(0, 0, "1234567890")
  FpSpread1.Sheets(0).SetValue(0, 1, "1234567890")
  FpSpread1.Sheets(0).SetValue(0, 2, "1234567890")
  FpSpread1.Sheets(0).SetValue(0, 3, "1234567890")
  FpSpread1.Sheets(0).SetValue(0, 4, "1234567890")
End Sub


◎サンプルコード(C#)
private void Form1_Load(object sender, EventArgs e)
{
  // エディタのタイプまたは選択ポリシーによって決定(デフォルト)
  FarPoint.Win.Spread.CellType.TextCellType txt_Inherit = new FarPoint.Win.Spread.CellType.TextCellType();
  txt_Inherit.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.Inherit;
  fpSpread1.Sheets[0].Cells[0, 0].CellType = txt_Inherit;

  // クリックした位置にカーソルを配置(Excelと同様の動作)
  FarPoint.Win.Spread.CellType.TextCellType txt_MouseLocation = new FarPoint.Win.Spread.CellType.TextCellType();
  txt_MouseLocation.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.MouseLocation;
  fpSpread1.Sheets[0].Cells[0, 1].CellType = txt_MouseLocation;

  // 常に先頭にカーソルを配置
  FarPoint.Win.Spread.CellType.TextCellType txt_FirstInputPosition = new FarPoint.Win.Spread.CellType.TextCellType();
  txt_FirstInputPosition.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.FirstInputPosition;
  fpSpread1.Sheets[0].Cells[0, 2].CellType = txt_FirstInputPosition;

  // 常に最後方にカーソルを配置
  FarPoint.Win.Spread.CellType.TextCellType txt_End = new FarPoint.Win.Spread.CellType.TextCellType();
  txt_End.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.End;
  fpSpread1.Sheets[0].Cells[0, 3].CellType = txt_End;

  // 文字列を全選択状態にする
  FarPoint.Win.Spread.CellType.TextCellType txt_SelectAll = new FarPoint.Win.Spread.CellType.TextCellType();
  txt_SelectAll.FocusPosition = FarPoint.Win.Spread.CellType.EditorFocusCursorPosition.SelectAll;
  fpSpread1.Sheets[0].Cells[0, 4].CellType = txt_SelectAll;

  fpSpread1.Sheets[0].SetValue(0, 0, "1234567890");
  fpSpread1.Sheets[0].SetValue(0, 1, "1234567890");
  fpSpread1.Sheets[0].SetValue(0, 2, "1234567890");
  fpSpread1.Sheets[0].SetValue(0, 3, "1234567890");
  fpSpread1.Sheets[0].SetValue(0, 4, "1234567890");
}