我正在使用devexpress工具。我有下面的代码基本上检查窗体上的每个控件,并通过检查值是否已更改为控件设置事件处理程序。在表单关闭时,它将检查是否为真,如果是,则提示保存。它现在工作正常,但我想检查gridcontrol中的gridview是否已更改。在gridview下有一个名为cellvaluechanged的事件。我想将处理程序添加到gridview.cellvaluechanged,但我无法直接访问它。它在网格控制中。我如何通过代码访问它?
'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
答案 0 :(得分: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