セル編集時にカーソルを文字列の最後に移動する

文書番号 : 17414     文書種別 : 使用方法     最終更新日 : 2005/04/29
文書を印刷する
対象製品
El Tabelle for .NET 3.0J
詳細
既に値が入力されている文字列型セルとコンボボックス型セルを編集するとき、El Tabelle for .NET (1.0) ではカーソル(キャレット)が文字列の末尾に設定されますが、El Tabelle for .NET 2.0 以降では文字列の先頭に設定されます。
この違いは、2.0 で日付型セルや数値型セルの動作に統一されたことによるものです。

El Tabelle for .NET (1.0) のようにカーソル(キャレット)を文字列の末尾に設定するには、次のようにコーディングを行います。

[Visual Basic]
Imports GrapeCity.Win.ElTabelle
Imports GrapeCity.Win.ElTabelle.Editors

Private Sub Sheet1_EnterEdit(ByVal sender As System.Object, _
  ByVal e As GrapeCity.Win.ElTabelle.EnterEditEventArgs) _
  Handles Sheet1.EnterEdit
  If TypeOf Sheet1.ActiveCell.Editor Is TextEditor Then
    '文字列型セル
    Dim objTextEditor As TextEditor
    objTextEditor = CType(Sheet1.ActiveCell.Editor, TextEditor)
    objTextEditor.CursorPosition = Sheet1.ActiveCell.Text.Length
    Sheet1.ActiveCell.Editor = objTextEditor
  ElseIf TypeOf Sheet1.ActiveCell.Editor Is ComboBoxEditor Then
    'コンボボックス型セル
    Dim objComboBoxEditor As ComboBoxEditor
    objComboBoxEditor = CType(Sheet1.ActiveCell.Editor, ComboBoxEditor)
    objComboBoxEditor.HighlightText = False
    objComboBoxEditor.SelectionStart = Sheet1.ActiveCell.Text.Length
    Sheet1.ActiveCell.Editor = objComboBoxEditor
  End If
End Sub


[C#]
using GrapeCity.Win.ElTabelle;
using GrapeCity.Win.ElTabelle.Editors;

private void sheet1_EnterEdit(object sender,
  GrapeCity.Win.ElTabelle.EnterEditEventArgs e)
{
  if((sheet1.ActiveCell.Editor as
    TextEditor) != null)
  {
    //文字列型セル
    TextEditor objTextEditor;
    objTextEditor = (TextEditor)sheet1.ActiveCell.Editor;
    objTextEditor.CursorPosition = sheet1.ActiveCell.Text.Length;
    sheet1.ActiveCell.Editor = objTextEditor;
  }
  else if((sheet1.ActiveCell.Editor as
    ComboBoxEditor) != null)
  {
    //コンボボックス型セル
    ComboBoxEditor objComboBoxEditor;
    objComboBoxEditor = (ComboBoxEditor)sheet1.ActiveCell.Editor;
    objComboBoxEditor.HighlightText = false;
    objComboBoxEditor.SelectionStart = sheet1.ActiveCell.Text.Length;
    sheet1.ActiveCell.Editor = objComboBoxEditor;
  }
}

MultiRowSheet の場合、次のようにコーディングします。

[Visual Basic]
Imports GrapeCity.Win.ElTabelle
Imports GrapeCity.Win.ElTabelle.Editors

Private Sub MultiRowSheet1_EnterEdit(ByVal sender As System.Object, _
  ByVal e As GrapeCity.Win.ElTabelle.MEnterEditEventArgs) _
  Handles MultiRowSheet1.EnterEdit
  If TypeOf MultiRowSheet1.ActiveCell.Editor Is TextEditor Then
    '文字列型セル
    Dim objTextEditor As TextEditor
    objTextEditor = CType(MultiRowSheet1.ActiveCell.Editor, TextEditor)
    objTextEditor.CursorPosition = MultiRowSheet1.ActiveCell.Text.Length
    MultiRowSheet1.ActiveCell.Editor = objTextEditor
  ElseIf TypeOf MultiRowSheet1.ActiveCell.Editor Is ComboBoxEditor Then
    'コンボボックス型セル
    Dim objComboBoxEditor As ComboBoxEditor
    objComboBoxEditor = CType(MultiRowSheet1.ActiveCell.Editor, ComboBoxEditor)
    objComboBoxEditor.HighlightText = False
    objComboBoxEditor.SelectionStart = MultiRowSheet1.ActiveCell.Text.Length
    MultiRowSheet1.ActiveCell.Editor = objComboBoxEditor
  End If
End Sub


[C#]
using GrapeCity.Win.ElTabelle;
using GrapeCity.Win.ElTabelle.Editors;

private void multiRowSheet1_EnterEdit(object sender,
  GrapeCity.Win.ElTabelle.MEnterEditEventArgs e)
{
  if((multiRowSheet1.ActiveCell.Editor as
    TextEditor) != null)
  {
    //文字列型セル
    TextEditor objTextEditor;
    objTextEditor = (TextEditor)multiRowSheet1.ActiveCell.Editor;
    objTextEditor.CursorPosition = multiRowSheet1.ActiveCell.Text.Length;
    multiRowSheet1.ActiveCell.Editor = objTextEditor;
  }
  else if((multiRowSheet1.ActiveCell.Editor as
    ComboBoxEditor) != null)
  {
    //コンボボックス型セル
    ComboBoxEditor objComboBoxEditor;
    objComboBoxEditor = (ComboBoxEditor)multiRowSheet1.ActiveCell.Editor;
    objComboBoxEditor.HighlightText = false;
    objComboBoxEditor.SelectionStart = multiRowSheet1.ActiveCell.Text.Length;
    multiRowSheet1.ActiveCell.Editor = objComboBoxEditor;
  }
}


※ イベントハンドラのコードは Visual Studio .NET で生成してください。
キーワード
HowTo

この文書は、以前は次のFAQ IDで公開されていました : 6974