Public Class Form26
    Dim printtype As Integer

   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.客户TableAdapter.Fill(Me.NorthwindDataSet.客户)
        D1.DataSource = Me.NorthwindDataSet.客户

        '表格字段名特殊格式设置打印测试
        D1.Columns(1).HeaderCell.Style.ForeColor = Color.Red
        Dim mystyle As FontStyle
        mystyle = FontStyle.Bold + FontStyle.Strikeout + FontStyle.Underline + FontStyle.Italic
        D1.Columns(1).HeaderCell.Style.BackColor = Color.Blue
        D1.Columns(1).HeaderCell.Style.Font = New Font("黑体", 13, mystyle)
        d1.Columns(3).HeaderCell.Style.BackColor = Color.Red



        '构建需要的数据（表格二），表格一为自动取数
        Dim i As Integer
        Dim j As Integer
        Dim mycol As DataGridViewColumn
        Dim myrow As DataGridViewRow
        Dim rows As Integer
        Dim cols As Integer

        cols = 2
        rows = 258
        d2.ColumnCount = cols
        d2.RowCount = rows
        '加一列按钮列
        For i = 0 To cols - 1
            mycol = d2.Columns(i)
            mycol.HeaderText = "第" + CStr(i + 1) + "列"
        Next
        Dim myco2 As New DataGridViewButtonColumn()
        myco2.HeaderText = "按钮列"
        myco2.Visible = True
        myco2.DefaultCellStyle.BackColor = Color.DarkGray
        d2.Columns.Add(myco2)

        d2.Rows(2).Cells(2).Style.ForeColor = Color.Blue
        d2.Rows(2).Cells(2).Style.Font = New Font("华文行楷", 12, FontStyle.Bold Or FontStyle.Strikeout Or FontStyle.Underline)
        cols = 3

        For i = 0 To cols - 1
            mycol = d2.Columns(i)
            mycol.HeaderText = "第" + CStr(i + 1) + "列"
        Next
        For i = 0 To rows - 1
            myrow = d2.Rows(i)
            For j = 0 To cols - 1
                myrow.Cells(j).Value = "第" + CStr(i + 1) + "行 第" + CStr(j + 1) + "列"
            Next

        Next

        d2.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        d2.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        d2.Rows(0).Cells(0).Value = "表格2"


    End Sub


    Private Sub 复制ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 复制ToolStripMenuItem.Click
        d1.Copy()
    End Sub

    Private Sub 粘贴ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 粘贴ToolStripMenuItem.Click
        d1.Paste()
    End Sub

    Private Sub 复制ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 复制ToolStripMenuItem1.Click
        d1.Copy(d2)
    End Sub

    Private Sub 粘贴ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 粘贴ToolStripMenuItem1.Click
        d1.Paste(d2) '在DataGridView2中执行粘贴
    End Sub
End Class