I opened this thread to ask some other issues regarding copy and paste in datagridview. This thread is based on this thread. the work of jeffcravener is working but i have some other concerns to wit:
1. Use the mouse right click button as an alternative way of pasting instead of just only using the keyboard.
2. If the datagridview has only one row, when pasting more than one value from excel, the datagrid will automatically create the rest of the row.
3. on load of the form, the datagridview's first cell is highlighted by default, How do make it display the blinking bar (|) without double clicking the cell.
Thanks in advance!
Code:Public Class Form1 Private Sub KeyPaste(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgvSRs.KeyDown If e.KeyCode = Keys.V And Keys.ControlKey Then Paste() End If End Sub Public Sub Paste() PasteData(dgvSRs) End Sub Public Sub PasteData(ByRef dgv As DataGridView) Dim tArr() As String Dim arT() As String Dim i, ii As Integer Dim c, cc, r As Integer tArr = Clipboard.GetText().Split(Environment.NewLine) r = dgv.SelectedCells(0).RowIndex c = dgv.SelectedCells(0).ColumnIndex For i = 0 To tArr.Length - 1 If tArr(i) <> "" Then arT = tArr(i).Split(vbTab) cc = c For ii = 0 To arT.Length - 1 If cc > dgv.ColumnCount - 1 Then Exit For If r > dgv.Rows.Count - 1 Then Exit Sub With dgv.Item(cc, r) .Value = arT(ii).TrimStart End With cc = cc + 1 Next r = r + 1 End If Next End Sub End Class




Reply With Quote