2016-04-11 41 views
0

我正在使用devexpress工具。我有下面的代碼,基本上檢查窗體上的每個控件,並通過檢查值是否已更改來設置控件的事件處理程序。在表格關閉時它會檢查這是否爲真,如果是,提示保存。它現在工作正常,但我想檢查gridcontrol內的gridview是否發生了變化。在gridview下有一個叫做cellvaluechanged的事件。我想將處理程序添加到gridview.cellvaluechanged,但我無法直接訪問它。它在一個gridcontrol裏面。我如何通過代碼訪問它?如何檢查gridview editvalue是否通過事件處理進行了更改

 '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 

這裏工作沒有gridview的檢查我的完整的解決方案

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

使用本:

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

或使用這個,如果你有GridControl 1周的GridView:

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