vb.net:datagridview是否具有与textbox.paste类似的功能?

时间:2014-10-07 13:57:19

标签: vb.net datagridview paste

我需要能够在我的光标所在的DataGridView单元格中添加一些文本。在TextBox上,我可以使用TextBox.Paste("test")执行此操作。我可以将单元格转换为TextBox还是有另一种方法?

例如: 当我有一个带有文本的单元格:“这是(光标在这里)一个例子”,然后我点击一个按钮tekst应该是:“这是一个例子”

1 个答案:

答案 0 :(得分:0)

自编辑以来,您的问题就更清晰了。此解决方案将文本插入DataGridViewCell中的最新光标位置。我点击按钮即可。您需要在表单上有一个名为DataGridView1的DataGridView和一个名为InsertTextBox的TextBox

Private lastTextBox As TextBox
Private lastCursorPosition As Integer
Private lastCell As DataGridViewCell

Private Sub InsertTextButton_Click(sender As Object, e As EventArgs) Handles InsertTextButton.Click
    If lastCell IsNot Nothing Then lastCell.Value = CType(lastCell.Value, String).Insert(lastCursorPosition, "test")
End Sub

Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
    lastTextBox = CType(e.Control, TextBox)
End Sub

Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
    lastCell = DataGridView1(e.ColumnIndex, e.RowIndex)
    lastCursorPosition = lastTextBox.SelectionStart
End Sub