Need code for "cut" command for in a ComboBox

tovia schlesinger 241 Reputation points
2021-02-17T18:57:27.707+00:00

I want to add the "cut" and "paste" feature to a ComboBox, and I am not finding the code for it. Can anyone provide me with "Cut" and "Paste" codes for ComboBox.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
0 comments No comments
{count} votes

Accepted answer
  1. Karen Payne MVP 35,401 Reputation points
    2021-02-17T22:14:50.38+00:00

    For a standard ComboBox, add a ContextMenyStrip to the form, add menu items, add code then set the ContextMenuStrip property of the ComboBox to the new ContextMenuStrip.

    69262-11111111111.png

    Code for copy and cut (you can figure out the rest)

    Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CopyToolStripMenuItem.Click  
        Clipboard.SetText(ComboBox1.Text)  
    End Sub  
    
    
    Private Sub CutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CutToolStripMenuItem.Click  
        Clipboard.SetText(ComboBox1.Text)  
        ComboBox1.Items.RemoveAt(ComboBox1.SelectedIndex)  
    End Sub  
    

    Following this link for other Clipboard methods
    https://video2.skills-academy.com/en-us/dotnet/api/system.windows.forms.clipboard.settext?view=net-5.0

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.