[英]how to print selected column in datagridview in vb.net?
如何在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中的所有行。
您沒有檢查該行是否可見。 您可能知道,編程語言可以與不可見的對象進行交互,因此僅因為不可見的對象並不意味着您的代碼將看不到它。
您可能只需要在Do While循環中放置一個條件...
Do WHile mRow < .RowCount
Dim row as DataGridViewRow = .Rows(mRow)
If row.Visible then
'blah blah blah
EndIf
Loop
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.