Получить первую видимую строку/ячейку в DataGridView в VB.NET

Чтобы получить первую видимую строку или ячейку в DataGridView в VB.NET, вы можете использовать различные методы. Вот несколько примеров кода:

  1. Метод 1: использование свойства FirstDisplayedScrollingRowIndex

    ' Get the index of the first visible row
    Dim firstVisibleRowIndex As Integer = dataGridView.FirstDisplayedScrollingRowIndex
    ' Get the first visible cell in the first visible row
    Dim firstVisibleCell As DataGridViewCell = dataGridView.Rows(firstVisibleRowIndex).Cells(0)
  2. Метод 2. Перебор видимых строк

    ' Iterate through the visible rows and find the first visible cell
    For Each row As DataGridViewRow In dataGridView.Rows
       If row.Visible Then
           Dim firstVisibleCell As DataGridViewCell = row.Cells(0)
           ' Do something with the first visible cell
           Exit For
       End If
    Next
  3. Метод 3. Использование метода GetCellDisplayRectangle

    ' Get the display rectangle of the top-left cell
    Dim displayRect As Rectangle = dataGridView.GetCellDisplayRectangle(0, 0, True)
    ' Get the row and column index of the first visible cell
    Dim firstVisibleRowIndex As Integer = dataGridView.HitTest(displayRect.Left, displayRect.Top).RowIndex
    Dim firstVisibleColumnIndex As Integer = dataGridView.HitTest(displayRect.Left, displayRect.Top).ColumnIndex
    ' Get the first visible cell
    Dim firstVisibleCell As DataGridViewCell = dataGridView.Rows(firstVisibleRowIndex).Cells(firstVisibleColumnIndex)

Это всего лишь несколько примеров того, как можно получить первую видимую строку или ячейку в DataGridView в VB.NET. Вы можете выбрать метод, который соответствует вашим конкретным требованиям, и использовать его соответственно.