Good day guys I need help for adding rows in datagrid where the rows to be added
are equal to the number of rows copied from excel. I can copy the data but it displays
only the first row from excel on the last row of datagrid but if I add let's just say 4
rows in datagrid 4 rows are copied from excel. What I want is to add rows equal
to the rows copied from excel to datagrid. If possible I f it can add another row
just like when you put data in a row it will automatically add one below the row you
are putting the data
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim s As String
Try
s = Clipboard.GetText()
Dim i, ii As Integer
Dim tArr() As String = s.Split(ControlChars.NewLine)
Dim arT() As String
Dim cc, iRow, iCol As Integer
iRow = DataGridView1.SelectedCells(0).RowIndex
iCol = DataGridView1.SelectedCells(0).ColumnIndex
For i = 0 To tArr.Length - 1
If tArr(i) <> "" Then
arT = tArr(i).Split(vbTab)
cc = iCol
For ii = 0 To arT.Length - 1
If cc > DataGridView1.ColumnCount - 1 Then Exit For
If iRow > DataGridView1.Rows.Count - 1 Then Exit Sub
With DataGridView1.Item(cc, iRow)
.Value = arT(ii).TrimStart
End With
cc = cc + 1
Next
iRow = iRow + 1
End If
Next
Catch ex As Exception
MsgBox("Please redo Copy and Click on cell")
End Try
End Sub
Source:http://franshbotes.blogspot.com/2011/07/paste-excel-data-into-datagrid-in-vbnet.html