Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows.Forms
Imports FarPoint.Win.Spread
Imports Spread.Common.DataStore
Imports Spread.Common.Features.Spread.Common.Features.Sample

Namespace Features
    Partial Public Class AutoCompleteDemo
        Inherits BaseSampleControl
        Private _autoCompleteStringcollection As AutoCompleteStringCollection
        Private _autoFillCellType As FarPoint.Win.Spread.CellType.GeneralCellType
        Private _textCellType As FarPoint.Win.Spread.CellType.TextCellType
        Private _previousColumn As Integer = -1
        Public Sub New()
            InitializeComponent()
            Name = "AutoComplete"
            InitializeControls()
            SetupSpreadSheet()
        End Sub
        Private Sub InitializeControls()
            dataSourceComboBox.DataSource = New String() {"CustomSource and All Column Items Below Cell", "CustomSource Only", "Column Items Below Cell Only"}
            dataSourceComboBox.SelectedIndex = 0

            modeComboBox.DataSource = [Enum].GetValues(GetType(AutoCompleteMode))
            modeComboBox.SelectedIndex = 3
        End Sub

        Private Sub SetupSpreadSheet()
            spread.Sheets(0).Columns.[Default].Width = 90
            spread.Sheets(0).Rows.[Default].Height = 25
            spread.DataSource = New DataService().AccessDataSource.GetNWINDData("Customers")

            Dim columnName As String = Nothing
            For Each column As Column In sheetView.Columns
                columnName = String.Format("{0}{1} ({2}) |", columnName, column.Label, column.Index)
            Next
            columnName = columnName.TrimEnd("|"c)
            applyColumnComboBox.DataSource = columnName.Split("|"c)
            applyColumnComboBox.SelectedIndex = 0

            Dim suggestionList As String() = "Benjamin,Bruce,Cheryl,Daniel,Dave,Eric,Hana,Harol,Henry,Jane,Jessica,John,Julia,Kathy,Lance,Laura,Mark,Marry,Meggie,Mike,Naomi,Paul,Peter,Roger,Rose,Ruth,Ryan,Shirley, Tan,Thomas,Tony, Varun, $1234, VND1234, 12345 %,13 %, 02/19/1991,Sunday, August 08, 2007,Saturday, March 09, 1997, February,0901234567,0953336650".Split(","c)
            customListBox.DataSource = suggestionList

            _autoCompleteStringcollection = New AutoCompleteStringCollection()
            _autoCompleteStringcollection.AddRange(suggestionList)
        End Sub
        Private Sub CustomAutoComplete(column As Integer, acm As Integer, AutoFillAutoCompleteCustomSource As Integer)
            _autoFillCellType = New FarPoint.Win.Spread.CellType.GeneralCellType()
            _autoFillCellType.AutoCompleteSource = AutoCompleteSource.CustomSource

            _textCellType = New FarPoint.Win.Spread.CellType.TextCellType()

            If AutoFillAutoCompleteCustomSource = 2 Then
                _autoFillCellType.AutoCompleteCustomSource = Nothing
            Else
                _autoFillCellType.AutoCompleteCustomSource = _autoCompleteStringcollection
            End If

            _autoFillCellType.AutoFillAutoCompleteCustomSource = AutoFillAutoCompleteCustomSource <> 1

            _autoFillCellType.AutoCompleteMode = CType(acm, AutoCompleteMode)
            spread.ActiveSheet.Columns(column).CellType = _autoFillCellType

            If _previousColumn >= 0 AndAlso _previousColumn <> column Then
                spread.ActiveSheet.Columns(_previousColumn).CellType = _textCellType
            End If

            _previousColumn = column
        End Sub
        Private Sub ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
            CustomAutoComplete(applyColumnComboBox.SelectedIndex, modeComboBox.SelectedIndex, dataSourceComboBox.SelectedIndex)
        End Sub
    End Class
End Namespace

'
'
'

Imports FarPoint.Win.Spread
Namespace Features
	Partial Class AutoCompleteDemo
		''' <summary> 
		''' Required designer variable.
		''' </summary>
		Private components As System.ComponentModel.IContainer = Nothing

        ''' <summary> 
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Sub Dispose(disposing As Boolean)
            If disposing AndAlso (components IsNot Nothing) Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub

#Region "Component Designer generated code"

        ''' <summary> 
        ''' Required method for Designer support - do not modify 
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
			Me.spread = New FarPoint.Win.Spread.FpSpread()
			Me.sheetView = New FarPoint.Win.Spread.SheetView()
			Me.autoCompleteGRBox = New System.Windows.Forms.GroupBox()
			Me.autoCompleteModeLabel = New System.Windows.Forms.Label()
			Me.applyColumnComboBox = New System.Windows.Forms.ComboBox()
			Me.customSourceLabel = New System.Windows.Forms.Label()
			Me.dataSourceComboBox = New System.Windows.Forms.ComboBox()
			Me.applyToColumnLabel = New System.Windows.Forms.Label()
			Me.modeComboBox = New System.Windows.Forms.ComboBox()
			Me.autoFillDataSourceLabel = New System.Windows.Forms.Label()
			Me.customListBox = New System.Windows.Forms.ListBox()
			Me.pnlMain.SuspendLayout()
			Me.pnlControls.SuspendLayout()
			DirectCast(Me.spread, System.ComponentModel.ISupportInitialize).BeginInit()
			DirectCast(Me.sheetView, System.ComponentModel.ISupportInitialize).BeginInit()
			Me.autoCompleteGRBox.SuspendLayout()
			Me.SuspendLayout()
			' 
			' pnlMain
			' 
			Me.pnlMain.Controls.Add(Me.spread)
			Me.pnlMain.Size = New System.Drawing.Size(626, 823)
			' 
			' pnlControls
			' 
			Me.pnlControls.AutoScroll = True
			Me.pnlControls.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
			Me.pnlControls.Controls.Add(Me.autoCompleteGRBox)
			Me.pnlControls.Size = New System.Drawing.Size(207, 823)
			' 
			' spread
			' 
			Me.spread.AccessibleDescription = ""
			Me.spread.Dock = System.Windows.Forms.DockStyle.Fill
			Me.spread.Location = New System.Drawing.Point(0, 0)
			Me.spread.Name = "spread"
			Me.spread.Sheets.AddRange(New FarPoint.Win.Spread.SheetView() {Me.sheetView})
			Me.spread.Size = New System.Drawing.Size(626, 823)
			Me.spread.TabIndex = 0
			' 
			' sheetView
			' 
			Me.sheetView.Reset()
			Me.sheetView.SheetName = "Sheet1"
			' Formulas and custom names must be loaded with R1C1 reference style
			Me.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1
			Me.sheetView.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1
			' 
			' autoCompleteGRBox
			' 
			Me.autoCompleteGRBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.autoCompleteGRBox.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
			Me.autoCompleteGRBox.Controls.Add(Me.autoCompleteModeLabel)
			Me.autoCompleteGRBox.Controls.Add(Me.applyColumnComboBox)
			Me.autoCompleteGRBox.Controls.Add(Me.customSourceLabel)
			Me.autoCompleteGRBox.Controls.Add(Me.dataSourceComboBox)
			Me.autoCompleteGRBox.Controls.Add(Me.applyToColumnLabel)
			Me.autoCompleteGRBox.Controls.Add(Me.modeComboBox)
			Me.autoCompleteGRBox.Controls.Add(Me.autoFillDataSourceLabel)
			Me.autoCompleteGRBox.Controls.Add(Me.customListBox)
			Me.autoCompleteGRBox.Location = New System.Drawing.Point(5, 23)
			Me.autoCompleteGRBox.Name = "autoCompleteGRBox"
			Me.autoCompleteGRBox.Size = New System.Drawing.Size(150, 309)
			Me.autoCompleteGRBox.TabIndex = 0
			Me.autoCompleteGRBox.TabStop = False
			Me.autoCompleteGRBox.Text = "AutoComplete"
			' 
			' autoCompleteModeLabel
			' 
			Me.autoCompleteModeLabel.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.autoCompleteModeLabel.AutoSize = True
			Me.autoCompleteModeLabel.Location = New System.Drawing.Point(6, 37)
			Me.autoCompleteModeLabel.Name = "autoCompleteModeLabel"
			Me.autoCompleteModeLabel.Size = New System.Drawing.Size(106, 13)
			Me.autoCompleteModeLabel.TabIndex = 34
			Me.autoCompleteModeLabel.Text = "AutoComplete Mode:"
			' 
			' applyColumnComboBox
			' 
			Me.applyColumnComboBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.applyColumnComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
			Me.applyColumnComboBox.FormattingEnabled = True
			Me.applyColumnComboBox.Location = New System.Drawing.Point(9, 53)
			Me.applyColumnComboBox.Name = "applyColumnComboBox"
			Me.applyColumnComboBox.Size = New System.Drawing.Size(121, 21)
			Me.applyColumnComboBox.TabIndex = 37
			AddHandler Me.applyColumnComboBox.SelectedIndexChanged, New System.EventHandler(AddressOf Me.ComboBox_SelectedIndexChanged)
			' 
			' customSourceLabel
			' 
			Me.customSourceLabel.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.customSourceLabel.AutoSize = True
			Me.customSourceLabel.Location = New System.Drawing.Point(6, 86)
			Me.customSourceLabel.Name = "customSourceLabel"
			Me.customSourceLabel.Size = New System.Drawing.Size(110, 13)
			Me.customSourceLabel.TabIndex = 38
			Me.customSourceLabel.Text = "Custom Source Items:"
			' 
			' dataSourceComboBox
			' 
			Me.dataSourceComboBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.dataSourceComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
			Me.dataSourceComboBox.FormattingEnabled = True
			Me.dataSourceComboBox.Location = New System.Drawing.Point(9, 102)
			Me.dataSourceComboBox.Name = "dataSourceComboBox"
			Me.dataSourceComboBox.Size = New System.Drawing.Size(121, 21)
			Me.dataSourceComboBox.TabIndex = 33
			AddHandler Me.dataSourceComboBox.SelectedIndexChanged, New System.EventHandler(AddressOf Me.ComboBox_SelectedIndexChanged)
			' 
			' applyToColumnLabel
			' 
			Me.applyToColumnLabel.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.applyToColumnLabel.AutoSize = True
			Me.applyToColumnLabel.Location = New System.Drawing.Point(6, 130)
			Me.applyToColumnLabel.Name = "applyToColumnLabel"
			Me.applyToColumnLabel.Size = New System.Drawing.Size(87, 13)
			Me.applyToColumnLabel.TabIndex = 36
			Me.applyToColumnLabel.Text = "Apply To Column"
			' 
			' modeComboBox
			' 
			Me.modeComboBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.modeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
			Me.modeComboBox.FormattingEnabled = True
			Me.modeComboBox.Location = New System.Drawing.Point(9, 146)
			Me.modeComboBox.Name = "modeComboBox"
			Me.modeComboBox.Size = New System.Drawing.Size(121, 21)
			Me.modeComboBox.TabIndex = 35
			AddHandler Me.modeComboBox.SelectedIndexChanged, New System.EventHandler(AddressOf Me.ComboBox_SelectedIndexChanged)
			' 
			' autoFillDataSourceLabel
			' 
			Me.autoFillDataSourceLabel.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.autoFillDataSourceLabel.AutoSize = True
			Me.autoFillDataSourceLabel.Location = New System.Drawing.Point(6, 182)
			Me.autoFillDataSourceLabel.Name = "autoFillDataSourceLabel"
			Me.autoFillDataSourceLabel.Size = New System.Drawing.Size(104, 13)
			Me.autoFillDataSourceLabel.TabIndex = 32
			Me.autoFillDataSourceLabel.Text = "AutoFill Data Source"
			' 
			' customListBox
			' 
			Me.customListBox.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
			Me.customListBox.FormattingEnabled = True
			Me.customListBox.Location = New System.Drawing.Point(9, 198)
			Me.customListBox.Name = "customListBox"
			Me.customListBox.Size = New System.Drawing.Size(121, 95)
			Me.customListBox.TabIndex = 39
			' 
			' AutoCompleteDemo
			' 
			Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 13F)
			Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
			Me.Name = "AutoCompleteDemo"
			Me.Size = New System.Drawing.Size(834, 823)
			Me.pnlMain.ResumeLayout(False)
			Me.pnlControls.ResumeLayout(False)
			DirectCast(Me.spread, System.ComponentModel.ISupportInitialize).EndInit()
			DirectCast(Me.sheetView, System.ComponentModel.ISupportInitialize).EndInit()
			Me.autoCompleteGRBox.ResumeLayout(False)
			Me.autoCompleteGRBox.PerformLayout()
			Me.ResumeLayout(False)

		End Sub

		#End Region
		Private spread As FpSpread
		Private sheetView As SheetView
		Private autoCompleteGRBox As System.Windows.Forms.GroupBox
		Private autoCompleteModeLabel As System.Windows.Forms.Label
		Private applyColumnComboBox As System.Windows.Forms.ComboBox
		Private customSourceLabel As System.Windows.Forms.Label
		Private dataSourceComboBox As System.Windows.Forms.ComboBox
		Private applyToColumnLabel As System.Windows.Forms.Label
		Private modeComboBox As System.Windows.Forms.ComboBox
		Private autoFillDataSourceLabel As System.Windows.Forms.Label
		Private customListBox As System.Windows.Forms.ListBox
	End Class
End Namespace
