yuvaratna
asked on
Required field validation In datagrid view Columns
i am working on windows application, using VB.Net. How can i Implement required field validation in dataGrdiview columns. The user should not be able to submit the form until he selected index is changed from the combobox or Something is enterd in the textbox...
The CellValidating event with the e.Cancel = True forces the user to enter something
ASKER
How can i show a message box if the user hasnt entered anything....should i check the value to string.empty and then display the user a message that the textbox cant be empty????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot ipaulino..give me a minute...I will check if it works....
Assuming your validating the 3rd column of the datagridview, use the below code which uses the RowValidating event
Private Sub DataGridView1_RowValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.RowValidating
If Not DataGridView1.Rows(e.RowIndex).IsNewRow Then
Dim c As DataGridViewCell = DataGridView1.Rows(e.RowIndex).Cells(2)
If IsDBNull(c.Value) Or c.Value = "" Then
c.ErrorText = "Cell cannot be empty" ' or msgbox("Cell cannot be empty") as u prefer
e.Cancel = True
Else
c.ErrorText = ""
e.Cancel = False
End If
End If
End Sub