简体   繁体   English

从datagridview检索文本时,对象引用未设置为对象的实例

[英]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.

相关问题 对象引用未设置为对象datagridview的实例 - object reference not set to an instance of object datagridview 未将对象引用设置为 DataGridView 的 InitializeEditingControlValue 中的对象实例 - Object reference not set to an instance of an object in InitializeEditingControlValue of a DataGridView 对象引用未设置为访问DataGridView的对象的实例 - Object reference not set to an instance of an object accessing DataGridView 对象引用未设置为对象的实例-DataGridView - Object reference not set to an instance of an object - datagridview 更改DataGridView颜色时,对象引用未设置为对象的实例 - Object reference not set to an instance of an object when changing DataGridView colors 过滤dataGridView时“对象引用未设置为对象的实例” - “Object reference not set to an instance of an object” when filtering dataGridView DataGridView.Datasource = null; 错误:对象引用未设置为对象的实例 - DataGridView.Datasource = null; ERROR: Object reference not set to an instance of an object 在C#中遍历DataGridView-对象引用未设置为对象的实例 - iterating over a DataGridView in C# - Object reference not set to an instance of an object c#datagridview对象引用未设置为对象的实例 - c# datagridview Object reference not set to an instance of an object 将数据从Excel导入到Visual Studio dataGridView。 得到此错误对象引用未设置为对象的实例 - Importing data from Excel to Visual studio dataGridView. Get this error Object reference not set to an instance of an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM