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.XtraGrid.Views.Base
Imports DevExpress.Data.Filtering
Imports DevExpress.XtraGrid

Public Class AutoFilterRowControllerVC
	Inherits DevExpress.ExpressApp.ViewController
    Private currentView As ListView
    Private gridView As ColumnView
    Private falseCriteria As CriteriaOperator = CriteriaOperator.Parse("1=0")

	Public Sub New()
		MyBase.New()

		'This call is required by the Component Designer.
		InitializeComponent()
		RegisterActions(components) 

    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        'If View.Id = "ProductFinder_ProductSelect_ListView" Then
        '    currentView = CType(View, ListView)
        '    AddHandler currentView.ControlsCreated, AddressOf AutoFilterRowController_ControlsCreated
        'End If
    End Sub
    Private Sub AutoFilterRowController_ControlsCreated(ByVal sender As Object, ByVal e As EventArgs)
        Dim grid As GridControl = TryCast(currentView.Control, GridControl)
        gridView = TryCast(grid.FocusedView, ColumnView)
        If gridView.ActiveFilter.IsEmpty Then
            currentView.CollectionSource.Criteria("FalseCriteria") = falseCriteria
        End If
        AddHandler gridView.ActiveFilter.Changed, AddressOf ActiveFilter_Changed
    End Sub
    Private Sub ActiveFilter_Changed(ByVal sender As Object, ByVal e As EventArgs)
        If (CType(sender, ViewFilter)).IsEmpty Then
            currentView.CollectionSource.Criteria("FalseCriteria") = falseCriteria
        Else
            If currentView.CollectionSource.Criteria.ContainsKey("FalseCriteria") Then
                currentView.CollectionSource.Criteria.Remove("FalseCriteria")
            End If
        End If
    End Sub

End Class
