【发布时间】:2016-04-11 18:40:40
【问题描述】:
我正在使用 devexpress 工具。我有下面的代码,它基本上检查表单上的每个控件,并通过检查值是否已更改来为控件设置事件处理程序。表单关闭时,它将检查这是否为真,如果是,则提示保存。它现在工作正常,但我想检查网格控件中的网格视图是否已更改。在 gridview 下有一个名为 cellvaluechanged 的事件。我想将处理程序添加到 gridview.cellvaluechanged,但我无法直接访问它。它在一个gridcontrol里面。我如何通过代码访问它?
'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
【问题讨论】:
标签: vb.net devexpress