我想求教DataGridView1里面可见行能有多少行,先求得可见行数
DataGridView1控件名称为dv1
Private Sub 数据_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Me.dv1.Height = Me.Height
Me.dv1.Width = Me.Width
End Sub
DataGridV Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Me.Show()
我想求教dv1里面可见行能有多少行,先求得可见行数
Dv1.ColumnCount = 50
Dv1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Dv1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
For i = 1 To 49
If i <= 6 Then
Dv1.Columns(i).DefaultCellStyle.BackColor = Color.Chocolate
End If
If i > 6 And i <= 11 Then
Dv1.Columns(i).DefaultCellStyle.BackColor = Color.DarkKhaki
End If
If i > 11 And i <= 16 Then
Dv1.Columns(i).DefaultCellStyle.BackColor = Color.DarkCyan
End If
If i > 16 And i <= 22 Then
Dv1.Columns(i).DefaultCellStyle.BackColor = Color.DarkGreen
Dv1.Columns(i).DefaultCellStyle.ForeColor = Color.Cyan
End If
If i > 22 And i <= 27 Then
Dv1.Columns(i).DefaultCellStyle.BackColor = Color.DarkOrange
Dv1.Columns(i).DefaultCellStyle.ForeColor = Color.Yellow
End If
If i > 27 And i <= 33 Then
Dv1.Columns(i).DefaultCellStyle.BackColor = Color.LightYellow
End If
If i > 33 And i <= 49 Then
Dv1.Columns(i).DefaultCellStyle.BackColor = Color.Cyan
End If
Next
Dv1.ReadOnly = True
Dv1.Rows.Add(UBound(sjsz, 2) - 1)
' dv1.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)
For i = 0 To 49
If i = 0 Then
Dv1.Columns(i).HeaderText = "序号"
Dv1.Columns(i).Width = Me.Width * 0.05
End If
If i > 0 And i < 34 Then
Dv1.Columns(i).HeaderText = i.ToString("00")
Dv1.Columns(i).Width = Me.Width * 0.94 / 50
End If
If i >= 34 Then
Dv1.Columns(i).HeaderText = (i - 33).ToString("00")
Dv1.Columns(i).Width = Me.Width * 0.94 / 50
End If
Next
‘ ProgressBar1.Minimum = 0
’ ProgressBar1.Maximum = UBound(sjsz, 2) - 1
For i = 0 To UBound(sjsz, 2) - 1
‘ ProgressBar1.Value = i
' dv1.Rows(i).HeaderCell.Value = (UBound(sjsz, 2) - 1 - i).ToString
Dv1.Rows.Item(i).Cells(0).Value = sjsz(0, UBound(sjsz, 2) - 1 - i)
Dv1.Rows.Item(i).Cells(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 1, 2))).Value = Val(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 1, 2)).ToString("00")
Dv1.Rows.Item(i).Cells(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 3, 2))).Value = Val(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 3, 2)).ToString("00")
Dv1.Rows.Item(i).Cells(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 5, 2))).Value = Val(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 5, 2)).ToString("00")
Dv1.Rows.Item(i).Cells(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 7, 2))).Value = Val(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 7, 2)).ToString("00")
Dv1.Rows.Item(i).Cells(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 9, 2))).Value = Val(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 9, 2)).ToString("00")
Dv1.Rows.Item(i).Cells(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 11, 2))).Value = Val(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 11, 2)).ToString("00")
Dv1.Rows.Item(i).Cells(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 13, 2)) + 33).Value = Val(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 13, 2)).ToString("00")
newlist.Add(CInt(Mid(sjsz(2, UBound(sjsz, 2) - 1 - i), 13, 2)) + 33)
Next
Dv1.Visible = True
End Sub
dim n as integer '可见行索引
for i as integer=0 to Dv1.Rows.Count-1
if(not Dv1.Rows(i).Visible)
n=i-1
exit for
end if
next
MessageBox.Show("可见" & (n+1) & "行");