ListView Click Cell Editor

Private Sub ListView42_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView42.MouseDoubleClick

        'detect clicked subitem / column

        Dim hit As ListViewHitTestInfo = ListView42.HitTest(e.X, e.Y)

        For Each lItem As ListViewItem In ListView42.Items

            If lItem.Selected = True Then

                For a = 0 To lItem.SubItems.Count

                    If hit.SubItem.Tag = lItem.SubItems(a).Tag Then

                        selCol = a

                        'prevent edit on first column

                        If selCol = 0 Then Exit Sub

                        'dim size and location of the TextBox

                        'TextBox.FontSize maybe 1 bigger than that of

                        'Listview Items to get the users eye catched on it.

                        TextBox42.Left = ListView42.Left + hit.SubItem.Bounds.Left + 3

                        TextBox42.Top = ListView42.Top + hit.SubItem.Bounds.Top

                        TextBox42.Width = hit.SubItem.Bounds.Width

                        TextBox42.Text = hit.SubItem.Text

                        'set TextBox to visible for user input

                        TextBox42.Visible = True



                        Exit For

                    End If


            End If


    End Sub

    Private Sub TextBox42_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox42.KeyPress

        'call LostFocus Sub in the event user pressed RETURN

        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then

            TextBox42_LostFocus(sender, Nothing)

        End If

    End Sub

    Private Sub TextBox42_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox42.LostFocus


        Dim selDetail As String

        'hide textbox

        TextBox42.Visible = False

        'load old value to detect if there is a change

        selDetail = ListView42.SelectedItems(0).SubItems(selCol).Text

        'change the subitem.text only if the new value is different to the existing one

        'to prevent display of the save butten without changing values

        If selDetail <> TextBox42.Text Then

  ListView42.Items(ListView42.SelectedItems(0).Index).SubItems(selCol).Text = TextBox42.Text

            'set change flag for not stored information to prevent loss of update by change of selection

            'changeFlage = True

            btnSave.Visible = True

        End If

        'do not clear the TextBox.Text, dueto LostFocus Sub may be called twice

        '(e.g. click mouse on a control different as the ListView)

        'else the list subitem.text will be overwritten again by an empty string

    End Sub