
Public Class ThisWorkbook

    Private Sub ThisWorkbook_Startup() Handles Me.Startup
        LsView.RightToLeft = RightToLeft.Yes
        LsView.MultiSelect = False
        LsView.View = View.SmallIcon
        LsView.RightToLeftLayout = True
        LsView.Height = 3 * ActionsPane.Height

        txtBox.RightToLeft = RightToLeft.Yes

        AddHandler txtBox.TextChanged, AddressOf txtBox_TextChanged
        AddHandler LsView.SelectedIndexChanged, AddressOf LsBox_SelectedIndexChanged

        Me.ActionsPane.Controls.Add(GlobalVars.txtBox)
        Me.ActionsPane.Controls.Add(GlobalVars.LsView)

        getItems()
        fillLsVeiw()

    End Sub
    Private Sub txtBox_TextChanged(sender As Object, e As EventArgs)
        Dim txt As String = txtBox.Text.Trim
        LsView.Items.Clear()
        fillLsVeiw(txt)
    End Sub
    Private Sub getItems()
        Dim IdRange As Excel.Range = Globals.Sheet1.Range("A2")
        Dim NameRange As Excel.Range = Globals.Sheet1.Range("B2")
        Dim LastNameRange As Excel.Range = Globals.Sheet1.Range("C2")

        Do While (IdRange.Value2 <> vbNullString)
            Dim node As LinkedListNode(Of Person) = New LinkedListNode(Of Person)(New Person)

            node.Value.ID = IdRange.Value2
            node.Value.IdRange = IdRange
            node.Value.NameRane = NameRange
            node.Value.LastNameRane = LastNameRange
            PersonsLinkedList.AddLast(node)

            IdRange = IdRange.Offset(1, 0)
            NameRange = NameRange.Offset(1, 0)
            LastNameRange = LastNameRange.Offset(1, 0)
        Loop
    End Sub
    Private Sub fillLsVeiw(Optional SearchSTR As String = vbNullString)
        If SearchSTR = vbNullString Then 'ADD All items
            Dim CurNode As LinkedListNode(Of Person) = PersonsLinkedList.First
            Do While CurNode IsNot Nothing
                Dim lsvItem As New ListViewItem
                lsvItem.Text = CurNode.Value.ID.ToString _
          + " " + CurNode.Value.NameRane.Value2 _
          + " " + CurNode.Value.LastNameRane.Value2
                lsvItem.Tag = CurNode.Value.ID.ToString
                LsView.Items.Add(lsvItem)
                CurNode = CurNode.Next
            Loop

        Else
            Dim CurNode As LinkedListNode(Of Person) = PersonsLinkedList.First
            Do While CurNode IsNot Nothing
                If CurNode.Value.LastNameRane.Value2.ToString.Contains(SearchSTR) _
         Or CurNode.Value.NameRane.Value2.ToString.Contains(SearchSTR) Then
                    Dim lsvItem As New ListViewItem
                    lsvItem.Text = CurNode.Value.ID.ToString _
            + " " + CurNode.Value.NameRane.Value2 _
            + " " + CurNode.Value.LastNameRane.Value2
                    lsvItem.Tag = CurNode.Value.ID.ToString
                    LsView.Items.Add(lsvItem)
                End If
                CurNode = CurNode.Next
            Loop
        End If
    End Sub

    Private Sub LsBox_SelectedIndexChanged(sender As Object, e As EventArgs)
        selectitem()
    End Sub


    Private Sub selectitem()
        If LsView.SelectedItems.Count <> 0 Then
            Dim idx = LsView.SelectedItems.Item(0).Tag
            Dim per As Person = Nothing
            Dim enumerator As Collections.Generic.IEnumerator(Of Person) =
          PersonsLinkedList.GetEnumerator
            Do While enumerator.MoveNext
                If enumerator.Current.ID = idx Then
                    per = enumerator.Current
                    Exit Do
                End If
            Loop

            If per IsNot Nothing Then
                per.IdRange.EntireRow.Select()
            End If
        End If
    End Sub

    Private Sub ThisWorkbook_Shutdown() Handles Me.Shutdown

    End Sub

End Class
