這似乎是一個重復的問題,但我正在尋找一個特定的功能。我在 StackOverflow 和 Google 上查看了類似的問題,并嘗試使用許多不同的代碼示例,但到目前為止,沒有成功。
我正在做的事情:
Form1_Load,我呼叫一個函式,在DataGridView中顯示 "MyFolder "中所有檔案的檔案資訊。
我的代碼:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me. 加載
'Call Function To Display File Info From MyFolder:
DataGridView1.DataSource = Fileinfo_To_DataTable("C:Users" username "DocumentsMyAppMyFolder")
End Sub
'下一個按鈕:
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext. 點擊
If DataGridView1.SelectedRows(0).Index < DataGridView1.RowCount - 1 Then
MyDesiredIndex = DataGridView1.SelectedRows(0).Index 1
Else[/span].
MyDesiredIndex=0
End If
DataGridView1.ClearSelection()
DataGridView1.CurrentCell = DataGridView1.Rows(MyDesiredIndex).Cells(0)
DataGridView1.Rows(MyDesiredIndex).Selected=True。
結束 子
'Previous Button:
Private Sub btnPrev_Click(sender As Object, e As EventArgs) Handles btnPrev. 點擊
If DataGridView1.CurrentCell.RowIndex >= 0 And DataGridView1. CurrentCell.RowIndex <= DataGridView1.Rows.Count - 1 Then
For Each row As DataGridViewRow In DataGridView1.Rows
If Not row.IsNewRow Or vbNull Then
MyDesiredIndex = DataGridView1.SelectedRows(0).Index - 1。
End If
下一步 下一步
End If
DataGridView1.ClearSelection()
DataGridView1.CurrentCell = DataGridView1.Rows(MyDesiredIndex).Cells(0)
DataGridView1.Rows(MyDesiredIndex).Selected=True。
End Sub
問題是:
下一步按鈕以 "連續回圈 "的方式回圈所有DGV行,沒有例外。我所說的 "連續回圈 "是指我的程式在第一行(0)或最后一行不間斷地回圈所有行(即只要我繼續按 "下一步 "按鈕,就會發生回圈)。
上一頁按鈕只有在我首先使用 "下一頁 "按鈕來改變所選行(即第一>最后一行)時才會起作用。然后,點擊 "上一頁 "按鈕,將選定的行回傳到第一行(即Last > First)。
"System.ArgumentOutOfRangeException: 'Index was out of range. 必須是 非負數并且小于集合的大小。引數名稱。 index'"
- 解決超出范圍的例外。
- 解決回圈/流過所有行的問題?
我已經嘗試過的東西:
移動到第一行,而不是回圈瀏覽所有的行。
在資料網格視圖中移動到前一行

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/308293.html
標籤:
