[英]Object reference not set to an instance of an object on retrieving text from datagridview
I have a Datagridview that is bound to a database using binding source. 我有一个使用绑定源绑定到数据库的Datagridview。 I want to highlight the row or text that has the value that I am searching.
我要突出显示具有我要搜索的值的行或文本。 But for some reason, it gives me this error:
但是由于某种原因,它给了我这个错误:
Object reference not set to an instance of an object.
你调用的对象是空的。
It points to the line: 它指向这一行:
Dim cell As DataGridViewCell = (EmployeesDataGridView.Rows(gridRow).Cells(gridColumn))
昏暗的单元格作为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
I've read the meaning of this error, but I cannot correlate its meaning to my code. 我已经阅读了此错误的含义,但无法将其含义与代码关联。 Thanks.
谢谢。
Do it like; 做喜欢的;
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
Hope it helps...!!! 希望能帮助到你...!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.