25-11-17, 02:01 AM
(25-11-17, 01:43 AM)Rabeea Qbaha كتب :كود :
Private Sub Gridv1_to_gricv()
DataGridView1.CancelEdit()
DataGridView1.Columns.Clear()
DataGridView1.DataSource = Nothing
Dim sourceGrid As DataGridView = Me.DataGrid1
Dim targetGrid As DataGridView = Me.DataGridView1
'Copy all rows and cells.
Dim targetRows = New List(Of DataGridViewRow)
For Each sourceRow As DataGridViewRow In sourceGrid.Rows
If (Not sourceRow.IsNewRow) Then
Dim targetRow = CType(sourceRow.Clone(), DataGridViewRow)
'The Clone method do not copy the cell values so we must do this manually.
'See: https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewrow.clone(v=vs.110).aspx
For Each cell As DataGridViewCell In sourceRow.Cells
targetRow.Cells(cell.ColumnIndex).Value = cell.Value
Next
targetRows.Add(targetRow)
End If
Next
'Clear target columns and then clone all source columns.
targetGrid.Columns.Clear()
For Each column As DataGridViewColumn In sourceGrid.Columns
targetGrid.Columns.Add(CType(column.Clone(), DataGridViewColumn))
Next
'It's recommended to use the AddRange method (if available)
'when adding multiple items to a collection.
targetGrid.Rows.AddRange(targetRows.ToArray())
End Sub
السلام عليكم
شكرا جزيلا اخي الكريم علي المساعدة
وضعت الكود في المشروع
لكن يظهر معي خطأ كما بالمرفق
مع جزيل الشكر