How to check if a cell in a datagrid has data within it?

I have a Datagrid with 5 columns with many rows.

How would check to see if  a cell in the 4th column has data within it?

Basically, the user would do a mouse click on a blank cell from the 4th column and it would then insert the system time. Now, if user would try to click the same cell again, I would like an alert to popup  to inform them that they can't update that cell.

thanks!
LVL 2
Richard KreidlSoftware DeveloperAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CodeCruiserConnect With a Mentor Commented:
Try IsDBNull function or IsNothing Function

If Not IsDBNull(dgv.Rows(3).Cells(4).Value) Then
   If Not IsNothing(dgv.Rows(3).Cells(4).Value) Then
      If Not String.IsNullOrEmpty(dgv.Rows(3).Cells(4).Value) Then
         Messagebox.Show("Error")
      End If
    End If
End If
0
 
SawinerCommented:
the data from the cells can be obtained with row and column. Do note however data grid view prefer to go by row, meaning you first need to know the row, and then the column. You can also use a column name instead of index, however you need an index for the row:

Object value = dataGridView1.Rows[rowIndex].Cells[columnIndex].Value;
or
Object value = dataGridView1.Rows[rowIndex].Cells[columnName].Value;

vb.net:
Dim value as Object = dataGridView1.Rows(rowIndex).Cells(columnIndex).Value
or
Dim value as Object = dataGridView1.Rows(rowIndex).Cells(columnName).Value
0
 
Richard KreidlSoftware DeveloperAuthor Commented:
thanks!!
0
All Courses

From novice to tech pro — start learning today.