تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[كود] DataGridView Copy & Paste
#1
ربما تبحث عن كود لعمل نسخ من DataGridView الى اكسل او العكس

الكود هو 

Copy
كود :
Sub Copy(ByVal DGV As DataGridView)
       If DGV.GetCellCount(DataGridViewElementStates.Selected) > 0 Then
           Try
               DGV.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText
               Clipboard.SetDataObject(DGV.GetClipboardContent())
           Catch ex As System.Runtime.InteropServices.ExternalException
               MsgBox(ex.Message)
           End Try
       End If
   End Sub

Paste

كود :
   Private Sub Paste(ByVal DGV As DataGridView)
       DGV.Rows.Clear()
       DGV.Columns.Clear()
       Dim s As String
       Dim i, ii As Integer
       Dim arT() As String
       Try
           s = Clipboard.GetText()
           Dim tArr() As String = s.Split(ControlChars.NewLine)
           arT = tArr(0).Split(vbTab)
           Dim word As String
           For Each word In arT
               DGV.Columns.Add(word, word)
           Next
           Dim cc, iRow, iCol As Integer
           For i = 1 To tArr.Length - 2
               DGV.Rows.Add("")
               If tArr(i) <> "" Then
                   arT = tArr(i).Split(vbTab)
                   cc = iCol
                   For ii = 0 To arT.Length - 1
                       If cc > DGV.ColumnCount - 1 Then Exit For
                       If iRow > DGV.Rows.Count - 1 Then Exit Sub
                       With DGV.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
الرد }}}
#2
شكرا اخى  العزيز لكن فى اى حدث اضع هذا الكود
الرد }}}
تم الشكر بواسطة:
#3
(16-07-19, 10:28 PM)mo.fathi كتب : شكرا اخى  العزيز لكن فى اى حدث اضع هذا الكود

فى اى حدث اضع هذا الكود من فضلك
الرد }}}
تم الشكر بواسطة: asemshahen5



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم