Validating Editor in DevExpress Gridview
In this article, I will explain how to perform a ValidatingEditor in an xtragrid in VB.NET
If we are having a datagrid and we are trying to edit the cells.
Sometimes it occur that "Input string was not in a correct format" error with a cross symbol in the cell.
Mostly it occurs with numerical values and when we make the column null, the above said error occurs.
So what shall we do if we want to make the cell empty ?
To do that, write the following code for the particular grid.
Private Sub GridView1_ValidatingEditor(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs) Handles GridView1.ValidatingEditor
Dim view As GridView = CType(sender, GridView)
If view.FocusedColumn.FieldName = "id" Or _
view.FocusedColumn.FieldName = "phno" Then
If Not e.Value Is Nothing AndAlso e.Value = "" Then
e.Value = DBNull.Value
Now you can give null values to the cell.
Also, when storing those null values to the database, give the sql query like the following code :
For each drow as DataRow in dt.Rows
If Convert.ToString(drow("id")) = "" And _
Convert.ToString(drow("phno")) = "" Then
Dim sqlText as String = "UPDATE table SET id = " & "NULL" & _
" AND phno = " & "NULL"
so it will store Null in the database.
Some columns will not allow nulls.
In such cases 0 may be stored