【问题标题】:How to check if gridview editvalue changed through event handling如何通过事件处理检查gridview editvalue是否更改
【发布时间】: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


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2014-05-19
      • 2011-11-12
      • 2019-01-22
      • 1970-01-01
      • 2010-12-19
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多