⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fm_datagrid.vb

📁 这是一个数据库高级实例
💻 VB
字号:
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Imports System.Windows.Forms


Public Class FM_DataGrid
    Dim pDataSet As DataSet
    Dim pConn As OleDb.OleDbConnection


    Public Sub New()
        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。

        pConn = New OleDb.OleDbConnection
        pDataSet = New DataSet
    End Sub



    Private Sub DataGridView1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyUp
        If (e.Modifiers = Keys.Control) And (e.KeyCode = Keys.C) Then
            '   Clipboard.SetText(this.dvCustomer.GetClipboardContent().GetData(DataFormats.Text).ToString()); 
            DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithAutoHeaderText
            '  Clipboard.SetDataObject(Me.DataGridView1.GetClipboardContent())
            Clipboard.SetText(Me.DataGridView1.GetClipboardContent().GetData(DataFormats.Text).ToString())
        End If

        If (e.Modifiers = Keys.Control) And (e.KeyCode = Keys.V) Then
            Try
                Dim str As String
                str = Clipboard.GetText()
                If str = "" Then Exit Sub
                Dim lines As String()

                lines = str.Split(Chr(13))
                Dim line As String
                Dim Cells As String()
                Dim cell As String

                Dim i As Int32 = Me.DataGridView1.CurrentCell.RowIndex - 1
                Dim j0 As Int32 = Me.DataGridView1.CurrentCell.ColumnIndex
                Dim j As Int32

                

                For Each line In lines
                    i = i + 1

                    'If i < Me.DataGridView1.RowCount - 1 Then
                    '    Me.DataGridView1.Rows.Add()
                    'End If

                    If line.Trim() = "" Then Continue For
                    j = j0
                    Cells = line.Split(Chr(Keys.Tab))
                    For Each cell In Cells
                        Me.DataGridView1.Rows(i).Cells(j).Value = cell
                        j = j + 1
                    Next
                Next
            Catch ex As Exception
            End Try
        End If

        If (e.KeyCode = Keys.Delete) Then
            Dim i As Int32
            For i = 0 To Me.DataGridView1.SelectedCells.Count - 1
                Me.DataGridView1.SelectedCells.Item(i).Value = ""
            Next

        End If

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -