0
votes

I'm using devexpress tools. I have code below that basically checks each control on a form and sets an event handler to the control by check if the value has changed. upon form closing it will check if this is true and if it is, prompt to save. It works fine now, but i want to check if a gridview within a gridcontrol has changed. there is an event called cellvaluechanged under gridview. I want to add the handler to the gridview.cellvaluechanged, but i can't access it directly. It's inside a gridcontrol. how can i access this through code?

      'If TypeOf c Is GridControl Then
        '    Dim cb As GridControl = CType(c, GridControl)
        '    AddHandler cb.ViewCollection(0).GridControl ... dont know how to access gridview

        'End If

Here is my full solution working without the gridview check

 Dim is_Dirty As Boolean = False

 Private Sub AddDirtyEvent(ByVal ctrl As Control)

For Each c As Control In ctrl.Controls
    If TypeOf c Is TextEdit Then
        Dim tb As TextEdit = CType(c, TextEdit)
        AddHandler tb.EditValueChanged, AddressOf SetIsDirty

    End If
    'If TypeOf c Is ComboBoxEdit Then
    '    Dim cb As ComboBoxEdit = CType(c, ComboBoxEdit)
    '    AddHandler cb.SelectedIndexChanged, AddressOf SetIsDirty

    'End If
    If c.Controls.Count > 0 Then
        AddDirtyEvent(c)
    End If

Next

 End Sub

 Private Sub SetIsDirty(ByVal sender As System.Object, ByVal e As    System.EventArgs)
  is_Dirty = True
 End Sub

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs)     Handles Me.FormClosing

If is_Dirty = True Then
    Dim dr As DialogResult = MessageBox.Show("Do you want save changes before leaving?", "Closing Well Info", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2)
    If dr = Windows.Forms.DialogResult.Yes Then
        SimpleButtonSave.PerformClick()
          End If
End If
1

1 Answers

1
votes

use this :

If TypeOf c Is GridControl Then
    For Each gv As GridView In CType(c, GridControl).Views
        AddHandler gv.CellValueChanged, AddressOf SetIsDirty
    Next
End If

or use this if you have 1 GridView in GridControl :

If TypeOf c Is GridControl Then
    Dim gv As GridView = CType(c, GridControl).Views(0)
    AddHandler gv.CellValueChanged, AddressOf SetIsDirty
End If