Search code examples
gridviewdevexpressdevexpress-windows-ui

how to validate data being entered in pop-up from a gridview in devexpress


I have a gridview setup in DevExpress so that when I want to add an item to the grid, I have an edit form that pops up. I want to validate the data that I enter in the pop-up form.

I'm using the ValidatingEditor method because I want to make sure that columns that are number fields, only accept numbers and columns that accept string fields, only accept strings.

I'm trying to do to access the value that has been edited by doing this:

gvTaxes.ActiveEditor.EditValue.ToString()

So this would be the

Private Sub gvTaxes_ValidatingEditor(sender As Object, e As BaseContainerValidateEditorEventArgs) Handles gvTaxes.ValidatingEditor

    Dim strCurrentValue As String

    If Not IsDBNull(gvTaxes.ActiveEditor.EditValue.ToString()) Then

        strCurrentValue = gvTaxes.ActiveEditor.EditValue.ToString()

    End If

I get a NullReferenceException exception from the 'if' line. Any ideas.


Solution

  • use e.Value.ToString() instead of gvTaxes.ActiveEditor.EditValue.ToString() :

    If Not IsDBNull(e.Value.ToString()) Then
    
        strCurrentValue = e.Value.ToString()
    
    End If