1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
My.Computer.Clipboard.Clear()
My.Computer.Clipboard.SetText(ToolStripTextBox1.Text)
If My.Computer.Clipboard.ContainsText Then
ToolStripTextBox1.Text = My.Computer.Clipboard.GetText
End If
Dim rowSplitter As Char() = {vbCr, vbLf}
Dim columnSplitter As Char() = {vbTab}
Dim dataInClipboard As IDataObject = Clipboard.GetDataObject()
Dim stringInClipboard As String = CStr(dataInClipboard.GetData(DataFormats.Text))
Dim rowsInClipboard As String() = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries)
Dim r As Integer = Form6.DataGridView1.SelectedCells(0).RowIndex
Dim c As Integer = Form6.DataGridView1.SelectedCells(0).ColumnIndex
If (Form6.DataGridView1.Rows.Count < (r + rowsInClipboard.Length)) Then
Form6.DataGridView1.Rows.Add(r + rowsInClipboard.Length - Form6.DataGridView1.Rows.Count)
End If
Dim iRow As Integer = 0
While iRow < rowsInClipboard.Length
Dim valuesInRow As String() = rowsInClipboard(iRow).Split(columnSplitter)
Dim iCol As Integer = 0
While iCol < valuesInRow.Length
If (Form6.DataGridView1.ColumnCount - 1 >= c + iCol) Then
Form6.DataGridView1.Rows(r + iRow).Cells(c + iCol).Value = valuesInRow(iCol)
End If
iCol += 1
End While
iRow += 1
End While
End Sub |
Partager