Edit Cells in ListView

Add a textbox and name it TextOverlay


 Dim iRow, iCol as Integer


Private Sub TextOverlay_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Hanldes TextOverlay.TextChanged
ListView1.Items(iRow).SubItems(iCol).Text = TextOverlay.Text End Sub Private Sub ListView1_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick Dim hit As ListViewHitTestInfo = ListView1.HitTest(e.X, e.Y) Dim iWidth As Integer For iCol = 0 To hit.Item.SubItems.Count - 1 If hit.Item.SubItems(iCol).Bounds.Left <= e.X Then If iCol = 0 And hit.Item.SubItems.Count > 1 Then If e.X <= hit.Item.SubItems(1).Bounds.Left Then iWidth = hit.Item.SubItems(1).Bounds.Left Exit For End If ElseIf e.X <= hit.Item.SubItems(iCol).Bounds.Right Then iWidth = hit.Item.SubItems(iCol).Bounds.Width Exit For End If End If Next iRow = hit.Item.Index TextOverlay.Left = ListView1.Left + hit.SubItem.Bounds.Left + 3 TextOverlay.Top = ListView1.Top + hit.SubItem.Bounds.Top TextOverlay.Width = iWidth TextOverlay.Height = 18 TextOverlay.Text = hit.SubItem.Text TextOverlay.Visible = True TextOverlay.ReadOnly = False End Sub
'https://stackoverflow.com/questions/10298551/make-a-cell-editable-in-a-listview

Add combobox to listview

Dim Combo As New ComboBox

Dim lvitem As ListViewItem = lstGroups.Items.Add("Add to the right -->")

        Combo.DropDownStyle = ComboBoxStyle.DropDown

        Combo.Height = lvitem.Bounds.Height

        Combo.Location = New Point(lvitem.Bounds.Right - 20, lvitem.Bounds.Y)

        AddHandler Combo.SelectedIndexChanged, AddressOf Combo_SelectedIndexChanged

        AddHandler Combo.KeyUp, AddressOf Combo_KeyUp

        'AddHandler Combo.sel AddressOf Combo_SelectedIndexChanged

        lstGroups.Controls.Add(Combo)


--

Private Sub Combo_SelectedIndexChanged(sender As Object, e As EventArgs)

        'Throw New NotImplementedException()

        Dim cmb As ComboBox = CType(sender, ComboBox)

     If cmb.Text = "Add to the right -->" Then Return

        If MsgBox("Add? " & cmb.Text, MsgBoxStyle.YesNo) = vbYes Then

            Dim lvItem As ListViewItem = lstGroups.Items.Add(cmb.Text)

            AddGroup(sServer, cmb.Text)

    End If

End Sub



Private Sub Combo_KeyUp(sender As Object, e As KeyEventArgs) 'Handles ComboBox1.KeyUp

        If e.KeyCode = Keys.Enter Then

            Combo_SelectedIndexChanged(sender, Nothing)

        End If

End Sub

Change Color of ListView cell (ListItem)

        Dim lvSu As ListViewItem = ListView1.Items(iRow) '.SubItems(iCol).item

        lvSu.UseItemStyleForSubItems = False

        lvSu.SubItems(iCol).ForeColor = Color.Red

Change Textbox to ComboBox with F3

textoverlay#_KeyDown

'----

ElseIf e.KeyCode = Keys.F3 Then

            TextOverlay2.Visible = False

            Dim lvItem As ListViewSubItem = lstAllLicenses.Items(iRow).SubItems(iCol)

            Dim Combo1 As New ComboBox

            Combo1.DropDownStyle = ComboBoxStyle.DropDown

            Combo1.Height = lvitem.Bounds.Height

            Combo1.Location = New Point(lvItem.Bounds.Left, lvItem.Bounds.Y)

            Combo1.Items.Add(lvItem.Tag)

            'Combo1.Items.Add("Test2")

            'Combo1.Items.Add("Test3")

            'Combo1.Items.Add("Test4")

            funGetAllDataFromField(lvItem.Tag, Combo1)

            Combo1.Text = lvItem.Text

            AddHandler Combo1.SelectedIndexChanged, AddressOf Combo1_SelectedIndexChanged

            AddHandler Combo1.KeyUp, AddressOf Combo1_KeyUp

            AddHandler Combo1.LostFocus, AddressOf Combo1_LostFocus

            lstAllLicenses.Controls.Add(Combo1)

        End If

        '----

Private Sub Combo1_KeyUp(sender As Object, e As KeyEventArgs) 'Handles ComboBox1.KeyUp

        If e.KeyCode = Keys.Enter Then

            Combo1_SelectedIndexChanged(sender, Nothing)

            Dim cmb As ComboBox = CType(sender, ComboBox)

            lstAllLicenses.Controls.Remove(cmb)

        End If

    End Sub

    Private Sub Combo1_LostFocus(sender As Object, e As EventArgs) '--Handles ComboBox1.LostFocus

        Combo1_SelectedIndexChanged(sender, Nothing)

        Dim cmb As ComboBox = CType(sender, ComboBox)

        lstAllLicenses.Controls.Remove(cmb)

    End Sub

    Private Sub Combo1_SelectedIndexChanged(sender As Object, e As EventArgs)

        'Throw New NotImplementedException()

        Dim cmb As ComboBox = CType(sender, ComboBox)

        Debug.Print("cmb.text: " & cmb.Text)

        'If cmb.Text = "Add to the right -->" Then Return

        lstAllLicenses.Items(iRow).SubItems(iCol).Text = cmb.Text

        'If MsgBox("Add? " & cmb.Text, MsgBoxStyle.YesNo) = vbYes Then

        '    Dim lvItem As ListViewItem = lstGroups.Items.Add(cmb.Text)

        '    AddGroup(sServer, cmb.Text)

        'End If

    End Sub