【问题标题】:how to print selected column in datagridview in vb.net?如何在 vb.net 的 datagridview 中打印选定的列?
【发布时间】:2014-06-05 10:48:08
【问题描述】:

如何在 vb.net 的 datagridview 中打印选定的列? 因为我想在 vb.net 中打印选定的行,这些行具有真正的可见性。 这是我在“PrintDocument1_PrintPage”中的代码,

With DataGridView1
    Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)

    fmt.LineAlignment = StringAlignment.Center
    fmt.Trimming = StringTrimming.EllipsisCharacter

    Dim y As Single = 190
    Do While mRow < .RowCount
        Dim row As DataGridViewRow = .Rows(mRow)
        Dim x As Single = 50
        Dim h As Single = 0
        For Each cell As DataGridViewCell In row.Cells


            Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)

            e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)

            e.Graphics.DrawString(DataGridView1.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Black, rc, fmt)

            x += rc.Width
            h = Math.Max(h, rc.Height)

        Next
        newpage = False
        y += h
        mRow += 1
        If y + h > e.MarginBounds.Bottom Then
            e.HasMorePages = True
            mRow -= 1
            newpage = True
            Exit Sub
        End If
    Loop
    mRow = 0

End With

-我的问题是,即使它具有错误的可见性,它也会打印我的 datagridview 中的所有行。

【问题讨论】:

    标签: vb.net printing datagridview


    【解决方案1】:

    您没有检查该行是否可见。您可能知道,编程语言可以与不可见的对象进行交互,因此不可见并不意味着您的代码不会看到它。

    您可能只需在 Do While 循环中放置一个条件...

    Do WHile mRow < .RowCount
    Dim row as DataGridViewRow = .Rows(mRow)
        If row.Visible then
            'blah blah blah
        EndIf
    Loop
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多