Cell validation on dropdowncell

3 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    157 posts
    Member since:
    Apr 2011

    Posted 26 Mar 2020 Link to this post


    I have a databound gridview in which I change two columns from standard cell to dropdown cells

    So far everything is fine, when I select a value in the dropdownlist, the grid is properly updated.

    However I need to validate the user's selection from the dropdown list and cancel the change if not authorized based on various conditions.

    I have tried various methods, such as using the callvalidating or cellvaluechanged events but I have not managed to cancel the change when not authorized. Moreover in some cases the dropdown is no longer available.

    As a workaround I perform the check in the cellvaluechanged event reload completely the grid when the change is not authorized but this is far from being efficient.

    Herebelow the code snipet of the celvaluechanged event


            Select Case e.Column.Name
                Case "Ctrldd"
                    Dim mEntry As New mEntry(MyConnectionString)
                    mEntry.UpdateCtrl(context, theEntry.idEntry, e.Value)
                Case "HCdd"
                    Dim mEntry As New mEntry(MyConnectionString)
                    If mEntry.CheckHCChange(theEntry, theCompetition.Label.Scope) Then
                        mEntry.UpdateHC(context, theEntry.idEntry, e.Value)
                        MessageBox.Show(My.Resources.Entry.ChangeHCNotAllowed, My.Resources.Main.WarningMsg, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        'request a reload of the grid
                        RaiseEvent RefreshRequired()
                    End If
            End Select

    Thanks in advance for any advice


  2. Nadya
    Nadya avatar
    482 posts

    Posted 31 Mar 2020 Link to this post

    Hello Pierre-Jean,

    According to the provided description, I can suggest you use the CellValidating event. It is raised by RadGridView when the current cell changes or when the cell loses input focus (when pressing Enter key). Canceling this event prevents the user from exiting the cell until a valid editor value is entered or the editing process is canceled:

    Private Sub radGridView1_CellValidating(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellValidatingEventArgs)
       ' cancel the event
        e.Cancel = True
    End Sub

    Please refer to the following help article concerning data validation: https://docs.telerik.com/devtools/winforms/controls/gridview/editors/data-validation

    I hope this information helps. If you need further assistance do not hesitate to contact us.

    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  3. pierre-jean
    pierre-jean avatar
    157 posts
    Member since:
    Apr 2011

    Posted 24 Apr 2020 in reply to Nadya Link to this post


    Finally I managed to perform the expected validation:

    in the CellEditorInitialized event :

                    Dim ddEditor As RadDropDownListEditor = e.ActiveEditor
                    ddEditor.EditorElement.Enabled = mEntry.CheckHCChange(theEntry, theCompetition.Label.Scope)

    thus if the CheckHCCChange function return false (indicating that the change is not allowed) the dropdownList editor is disabled

    Kind regards

Back to Top