This is a migrated thread and some comments may be shown as answers.

Cell validation on dropdowncell

2 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 26 Mar 2020, 02:30 PM

Hello

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)
                ShowEntryDetails(theEntry.idEntry)
            Case "HCdd"
                Dim mEntry As New mEntry(MyConnectionString)
                If mEntry.CheckHCChange(theEntry, theCompetition.Label.Scope) Then
                    mEntry.UpdateHC(context, theEntry.idEntry, e.Value)
                    ShowEntryDetails(theEntry.idEntry)
                Else
                    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

Pierre-Jean

2 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 31 Mar 2020, 10:49 AM

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.

Regards,
Nadya
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.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 24 Apr 2020, 04:49 PM

Hello

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

Tags
GridView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Share this question
or