文字列型セル(TextBoxCell)で編集時のキャレット位置を取得する方法
対象製品
MultiRow for Windows Forms 10.0J
詳細
編集時のキャレットの位置は、編集用コントロールのSelectionStartプロパティを使って取得できます。
下記のサンプルコードは、編集コントロールでキーを押下した時に現在のキャレット位置を取得する方法を示しています。
[Visual Basic]
[C#]
下記のサンプルコードは、編集コントロールでキーを押下した時に現在のキャレット位置を取得する方法を示しています。
[Visual Basic]
Imports GrapeCity.Win.MultiRow Private Sub GcMultiRow1_EditingControlShowing(ByVal sender As System.Object, ByVal e As GrapeCity.Win.MultiRow.EditingControlShowingEventArgs) Handles GcMultiRow1.EditingControlShowing If GcMultiRow1.CurrentCell.Name = "textBoxCell1" Then RemoveHandler e.Control.KeyPress, AddressOf Editor_KeyPress AddHandler e.Control.KeyPress, AddressOf Editor_KeyPress End If End Sub Private Sub Editor_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Dim editor As TextBoxEditingControl = sender Debug.Print(editor.SelectionStart) End Sub
[C#]
private void gcMultiRow1_EditingControlShowing(object sender, GrapeCity.Win.MultiRow.EditingControlShowingEventArgs e) { if (e.Control is TextBoxEditingControl) { TextBoxEditingControl text = e.Control as TextBoxEditingControl; text.KeyDown -= new KeyEventHandler(text_KeyDown); text.KeyDown += new KeyEventHandler(text_KeyDown); } } private void text_KeyDown(object sender, KeyEventArgs e) { TextBoxEditingControl editor = (TextBoxEditingControl)gcMultiRow1.EditingControl; Console.WriteLine(editor.SelectionStart); }