Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.Win.Editors
Imports DevExpress.XtraGrid.Columns

Public Class GLRowsDivideVC
    Inherits DevExpress.ExpressApp.ViewController(Of ListView)
    Private _GridListEditor As GridListEditor
    Public Sub New()
        MyBase.New()

        InitializeComponent()
        RegisterActions(components)

    End Sub
    Protected Overrides Sub OnViewControlsCreated()
        MyBase.OnViewControlsCreated()
        If View.Id = "GLRowsDivideH_GLRowsDivideR_ListView_ConnectionDivide" Then
            _GridListEditor = TryCast(View.Editor, GridListEditor)
            If _GridListEditor IsNot Nothing Then
                '_GridListEditor.AllowEdit = True
                'For i As Integer = 0 To _GridListEditor.Columns.Count - 1
                '    If _GridListEditor.GridView.Columns(i).FieldName <> "AmountHUF" And _
                '        _GridListEditor.GridView.Columns(i).FieldName <> "AmountDEV" Then
                '        _GridListEditor.GridView.Columns(i).OptionsColumn.ReadOnly = True
                '        _GridListEditor.GridView.Columns(i).OptionsColumn.AllowEdit = False
                '        _GridListEditor.GridView.Columns(i).OptionsColumn.TabStop = False
                '    End If
                'Next i
                AddHandler _GridListEditor.GridView.CellValueChanged, AddressOf _CellValueChanged
            End If
        End If
    End Sub
    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "GLRowsDivideH_GLRowsDivideR_ListView_ConnectionDivide" Then
            If _GridListEditor IsNot Nothing Then
                RemoveHandler _GridListEditor.GridView.CellValueChanged, AddressOf _CellValueChanged
            End If
        End If
    End Sub

    Private Sub _CellValueChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs)
        If TryCast(e.Column, GridColumn).FieldName = "AmountHUF" Or _
           TryCast(e.Column, GridColumn).FieldName = "AmountDEV" Then
            Dim nestedFrame As NestedFrame = TryCast(Frame, NestedFrame)
            If nestedFrame IsNot Nothing Then
                Dim parentView As View = nestedFrame.View
                TryCast(parentView.ObjectSpace, Xpo.XPObjectSpace).CommitChanges()
                parentView.ObjectSpace.Refresh()
            End If
        End If
    End Sub

End Class
