Click here to Skip to main content
15,887,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi, i want to test/check when cells in data gridview is empty and when clicked it shows label like "there's a empty data in cell", thanks before

VB
If dgvdatakaryawan.Item(e.ColumnIndex, e.RowIndex).Value.ToString.Length = Nothing Then
           lblKET.Visible = True
       Else
           lblKET.Visible = False
       End If


i mean i have lot of data, if in one rows have some blank data, and when rows is clicked it show label like above
Posted
Updated 10-Sep-17 9:44am
v3
Comments
Andy Lanng 15-Jun-15 4:13am    
Akbar Giffary 15-Jun-15 4:33am    
take a look please
Andy Lanng 15-Jun-15 4:42am    
Ok. I see. When does this segment run? is it in the page load?
Thanks ^_^
Akbar Giffary 15-Jun-15 5:00am    
in mouseclick on datagridview
Andy Lanng 15-Jun-15 5:13am    
Ah. datagrid views can be tricky with this. I had an issue with this on Friday.

What can happen is that the mouseclick event occurs before the datagrid data is bound. This would mean that the label is empty by the time you read it.

There are ways around this but first, please confirm that the bind event occurs after the mouseclick event.

1 solution

I think your If statement should look like this. It sets the lblKET to visible if the cell is Null or contains only spaces or an empty string.


VB
If dgvdatakaryawan.Item(e.ColumnIndex, e.RowIndex).Value Is Nothing orelse _
   dgvdatakaryawan.Item(e.ColumnIndex, e.RowIndex).Value.ToString.Trim = "" Then
     lblKET.Visible = True
Else
     lblKET.Visible = False
End If
 
Share this answer
 
v4
Comments
Akbar Giffary 15-Jun-15 20:50pm    
hmmm, many thanks,
but can i sets the lblKET to visible if the "selected rows" have some Null value or contains only spaces or an empty string ?

i mean when if i selected rows, not when cell is clicked..
Mike Meinz 16-Jun-15 6:36am    
If you want to select based on empty row, then you have to check each cell in that row. To do that, you iterate through all of the columns in that row and if they all satisfy the conditions in my sample code, then the row is "empty."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900