السلام عليكم الاخوة الاعزاء
برجاء المساعدة في كود لنقل المعلومات الموجودة في داتا جريد فيو رقم واحد الي الداتا جريد فيو رقم اثنان
بعد الضغط علي مفتاح Transefer
بحيث مثلا لو عملت فلتر في الداتا جريد فيو رقم واحد
ثم ضغطت علي مفتاح Transefer
تنقل فقط المعلومات الموجود في الداتا جريد فيو رقم واحد بعد الفلتر
برجاء فحص المرفقات
مع جزيل الشكر
(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
السلام عليكم
شكرا جزيلا اخي الكريم علي المساعدة
وضعت الكود في المشروع
لكن يظهر معي خطأ كما بالمرفق
مع جزيل الشكر
قمت بتحميل الملف والتعديل على الكود ليناسبك
فقط استدعي المثود Gridv1_to_gricv() في زر ال Transfere
كود :
Private Sub Gridv1_to_gricv()
DataGridView2.CancelEdit()
DataGridView2.Columns.Clear()
DataGridView2.DataSource = Nothing
Dim sourceGrid As DataGridView = Me.DataGridView1
Dim targetGrid As DataGridView = Me.DataGridView2
'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
(25-11-17, 02:20 AM)Rabeea Qbaha كتب : [ -> ]قمت بتحميل الملف والتعديل على الكود ليناسبك
فقط استدعي المثود Gridv1_to_gricv() في زر ال Transfere
كود :
Private Sub Gridv1_to_gricv()
DataGridView2.CancelEdit()
DataGridView2.Columns.Clear()
DataGridView2.DataSource = Nothing
Dim sourceGrid As DataGridView = Me.DataGridView1
Dim targetGrid As DataGridView = Me.DataGridView2
'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
تمام اخي الحبيب
الكود تمام التمام
ربنا يبارك فيك يارب مع جزيل الشكر
طيب يا اخى
مثالك هذا ممتاز جدا ولكن انا تواجهنى مشكلة كبيره قوى لو انا عايز انقل بيانات بعض أعمده من داتا جريد فيو الى داتا جريد فيو تانيه ولكن مرتبطه بداتا ست او داتا باوند كيف تكون الطريقة ساعدنى ارجوك