1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Globalization
Public Class NewDbg
Friend WithEvents _Dbg As DataGridView
Public Sub New(ByRef Dbgc As DataGridView)
Dbg = Dbgc
End Sub
Public Property Dbg As DataGridView
Get
Return _Dbg
End Get
Set(value As DataGridView)
_Dbg = DirectCast(value, System.Windows.Forms.Control)
AddHandler _Dbg.CellMouseDown, AddressOf MyDown
End Set
End Property
Private Sub MyDown(sender As Object, e As Windows.Forms.DataGridViewCellMouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Right Then
PasteClipboardw()
End If
End Sub
Private Sub PasteClipboardw()
Try
Dim s As String = Clipboard.GetText()
Dim lines As String() = s.Split(Environment.NewLine)
Dim iFail As Integer = 0, iRow = _Dbg.CurrentCell.RowIndex
Dim iCol As Integer = _Dbg.CurrentCell.ColumnIndex
Dim oCell As DataGridViewCell
Dim i As Integer = 0, c As Integer = 0
For i = 0 To lines.LongCount - 1
If iRow + i = _Dbg.RowCount Then
_Dbg.DataSource.Rows.Add(_Dbg.DataSource.NewRow())
_Dbg.Refresh()
End If
Next
i = 0
For Each line As String In lines
Dim sCells As String() = line.Split(Convert.ToChar(Keys.Tab))
c = 0
For Each Col As String In sCells
oCell = _Dbg(iCol + c, iRow + i)
oCell.Value = FormaterChamp(Convert.ChangeType(Col.ToString, oCell.ValueType))
c += 1
Next
i += 1
Next
_Dbg.Refresh()
Catch ex As Exception
End Try
End Sub
Private Function FormaterChamp(Champ As Object) As Object
Dim provider As CultureInfo = CultureInfo.InvariantCulture, e As Exception
Dim V As String = ""
Select Case Champ.GetType.Name
Case "DBNull" : Return "Null"
Case "Boolean" : Try : Return Boolean.Parse(Champ).ToString.Replace("True", True).Replace("False", False) : Catch e : End Try
Case "Decimal", "Int32" : Return Champ.ToString.Replace(",", ".")
Case "DateTime" : Try : Return "#" + Date.Parse(Champ) + "#" : Catch e : End Try
Case Else : Return Champ
End Select
Return Nothing
End Function
End Class |
Partager