I have a vb.net windows form application using a datagridview. I'm hoping to find a way to prevent a user from entering whitespaces or empty strings and if they enter invalid input. I'll have a message appear explaining their mistake and thereafter a default value will be supplied. This is what I have so far and it prevents completely blank cells but if I had a whitespace (i.e. press space bar to add blank string) it doesn't know that it's still blank input.
If (columnindex = 0) Then 'checking value for column 1 only
Dim cellString = DataGridView1.Rows(rowindex).Cells(columnindex).value
If cellString Is Nothing OrElse IsDBNull(cellString) OrElse cellString.ToString = String.Empty Then
MessageBox.Show("Cannot Be Empty")
DataGridView1.Rows(rowindex).Cells(columnindex).value = "Default Value"
Exit Sub
End If