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

Public Class InventoryVC_ListView
    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 = "InventoryHeader_InventorySC_ListView" Then
            _GridListEditor = TryCast(View.Editor, GridListEditor)

            If _GridListEditor IsNot Nothing Then
                AddHandler _GridListEditor.GridView.CellValueChanged, AddressOf InventoryHeader_InventorySC_ListView_CellValueChanged
            End If

            'If _GridListEditor IsNot Nothing Then
            '    _GridListEditor.AllowEdit = True
            '    For i As Integer = 0 To _GridListEditor.Columns.Count - 1
            '        If _GridListEditor.GridView.Columns(i).FieldName <> "QTT_Found" 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
            'End If
        End If
    End Sub

    Protected Overrides Sub OnDeactivated()
        MyBase.OnDeactivated()
        If View.Id = "InventoryHeader_InventorySC_ListView" Then
            If _GridListEditor IsNot Nothing Then
                RemoveHandler _GridListEditor.GridView.CellValueChanged, AddressOf InventoryHeader_InventorySC_ListView_CellValueChanged
            End If
        End If
    End Sub

    Private Sub InventoryHeader_InventorySC_ListView_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs)
        Dim nestedFrame As NestedFrame = TryCast(Frame, NestedFrame)
        If nestedFrame IsNot Nothing Then
            Dim parentView As View = nestedFrame.View
            parentView.ObjectSpace.CommitChanges()
            parentView.ObjectSpace.Refresh()
        End If
    End Sub
End Class
