简体   繁体   中英

object reference not set to an instance of object datagridview

The following error occured "Object reference not set to an instance of an object" when I tried below code. I don,t know why this error accours, as I used the same code on my other apps and they work fine but not working in this case. Please see whats the problem on it.

Very thanks for your time!

            For Each rows2 As DataGridViewRow In DataGridView1.Rows


            If InStr(rows2.Cells.Item("Status").Value.ToString, "Not Checked") Then

               DataGridView1.Rows.RemoveAt(rows2.Index.ToString)
            End If


        Next

Put a try/catch in your code, look at the ex and see what is nothing. It has to be an empty row or outside the bounds of your table somehow.

Also, why not just:

DataGridView1.Rows.RemoveAt(rows2.index)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM