[英]Object reference not set to an instance of an object on retrieving text from datagridview
我有一個使用綁定源綁定到數據庫的Datagridview。 我要突出顯示具有我要搜索的值的行或文本。 但是由於某種原因,它給了我這個錯誤:
你調用的對象是空的。
它指向這一行:
昏暗的單元格作為DataGridViewCell =(EmployeesDataGridView.Rows(gridRow).Cells(gridColumn))
Dim someText As String = txtSearchLastName.Text
Dim gridRow As Integer = 0
Dim gridColumn As Integer = 0
For Each Row As DataGridViewRow In EmployeesDataGridView.Rows
For Each column As DataGridViewColumn In EmployeesDataGridView.Columns
Dim cell As DataGridViewCell = (EmployeesDataGridView.Rows(gridRow).Cells(gridColumn))
If cell.Value.ToString.ToUpper.Contains(someText.ToUpper) Then
cell.Style.BackColor = Color.Yellow
End If
gridColumn += 1
Next column
gridColumn = 0
gridRow += 1
Next Row
我已經閱讀了此錯誤的含義,但無法將其含義與代碼關聯。 謝謝。
做喜歡的;
For Each row As DataGridViewRow In EmployeesDataGridView.rows
For Each cell As DataGridViewCell In row.cells
If cell.Value.ToString.ToUpper.Contains(someText.ToUpper) Then
cell.Style.BackColor = Color.Yellow
End If
Next
Next
希望能幫助到你...!!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.