I haven't tried this code on my own but my friend used this code to bring this functionality, I just wanted to share so that someone might get benifitted from this code
The code is in VB.NET
If (e.Control And e.KeyCode = Keys.V) Then
Dim s As String = Clipboard.GetText()
Dim lines As String()
lines = System.Text.RegularExpressions.Regex.Split(s, Environment.NewLine)
'Dim row As Integer = dgv.CurrentCell.RowIndex
'Dim col As Integer = dgv.CurrentCell.ColumnIndex
Dim row, col As Integer
For intRow As Integer = 0 To dgv.RowCount - 1
For intCol As Integer = 0 To dgv.ColumnCount - 1
If dgv.Rows(intRow).Cells(intCol).Selected = True Then
row = intRow
col = intCol
Exit For
End If
Next
If Not (row = 0 And col = 0) Then
Exit For
End If
Next
For intNextLine As Integer = 0 To (lines.Length - 1)
If (row < dgv.RowCount And lines(intNextLine).Length > 0) Then
Dim cells As String() = System.Text.RegularExpressions.Regex.Split(lines(intNextLine), "\t")
For i As Integer = 0 To cells.Length - 1
If (col + i < dgv.ColumnCount) Then
dgv.Rows(row).Cells(col + i).Value = cells(i)
End If
Next
row = row + 1
End If
Next
End If
No comments:
Post a Comment