|
■No88633 (まっさん さん) に返信
すみません。↑は間違って投稿してしまいました。
(c)以外は以下で、一応希望通りに動作しているように思います。
'編集中セルの行番号、列番号、EditingControl
Private _textbox As Tuple(Of Integer, Integer, DataGridViewTextBoxEditingControl)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("C1", GetType(Integer))
dt.Rows.Add(1)
dt.AcceptChanges()
DataGridView1.DataSource = dt
End Sub
Private Sub DataGridView1_DataError(sender As Object, e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
DataGridView1.Rows(e.RowIndex).ErrorText = "セルの値を確認してください。"
'念の為、行番号、列番号も照合する
If _textbox IsNot Nothing AndAlso _textbox.Item1 = e.RowIndex AndAlso _textbox.Item2 = e.ColumnIndex Then
_textbox.Item3.SelectAll()
End If
e.Cancel = True
End Sub
Private Sub DataGridView1_CellValidating(sender As Object, e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
If DataGridView1.Rows(e.RowIndex).ErrorText IsNot String.Empty Then
DataGridView1.Rows(e.RowIndex).ErrorText = String.Empty
End If
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, _
ByVal e As DataGridViewEditingControlShowingEventArgs) _
Handles DataGridView1.EditingControlShowing
If TypeOf e.Control Is DataGridViewTextBoxEditingControl Then
Dim tbox = DirectCast(e.Control, DataGridViewTextBoxEditingControl)
Dim cell = DataGridView1.CurrentCell
_textbox = Tuple.Create(cell.RowIndex, cell.ColumnIndex, tbox)
Else
_textbox = Nothing
End If
End Sub
Private Sub DataGridView1_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
DataGridView1.CurrentCell = Nothing
DataGridView1.CurrentCell = DataGridView1(e.ColumnIndex, e.RowIndex)
End Sub
|