Question Defining any cell within a selected row?

Oddism

Member
Joined
Nov 21, 2011
Messages
15
Programming Experience
Beginner
Hi, I've a feeling that there is a very simple way around this, however, I can't seem to find it...

Anyway, what I'm trying to do is to check every item's value in the current row for a null value, if one is found, the sub will be exited. Something like this:
If Not IsDBNull(DataGridView.Item(#, DataGridView.CurrentRow.Index).Value) Then

Do something()

Else : Exit Sub
End If

However, I would like to check every cell in the row as opposed to just one.

I assume that I shouldn't even be using the DataGridView.Item property since that does just check one item.

I guess I could loop around this, increasing the column index by one each time, but there must be a simpler way?

Any help would be appreciated!
Thanks.
 
The fact that you're looking for DBNull, suggest that this is bound data from a database. In that case, you should be working with the bound data, not the grid.
Dim view = DirectCast(myBindingSource.Current, DataRowView)
Dim row = view.Row

For Each column As DataColumn In row.Table.Columns
    If row.IsNull(column) Then
        Return
    End If
Next

'There are no null values in the row.
This assumes that the data is bound to the grid via a BindingSource. If it's not, it should be.
 
Your assumption was correct and this works perfectly for what I was trying to achieve.

Thanks, you did it again!! :)
 
Back
Top