Hi @Mansour_Dalir ,
You can create a new class inherits ContextMenuStrip that encapsulates the functionality.
Public Class AdvancedContextMenu
Inherits ContextMenuStrip
Private WithEvents txtFilter As New TextBox
Private WithEvents chkListBoxSelect As New CheckedListBox
Public Sub New()
MyBase.New()
InitializeComponents()
End Sub
Private Sub InitializeComponents()
Me.AutoSize = True
Me.ShowImageMargin = False
chkListBoxSelect.MaximumSize = New Size(0, 200)
chkListBoxSelect.Items.AddRange({"Item 1 xx", "Item 2", "Item 3", "Item 4 xxxxx", "Item 5"})
txtFilter.MinimumSize = New Size(200, 0)
txtFilter.Width = 200
Me.Items.Add(New ToolStripControlHost(txtFilter) With {.AutoSize = False})
Me.Items.Add(New ToolStripControlHost(chkListBoxSelect) With {.AutoSize = False})
End Sub
Private Sub txtFilter_TextChanged(sender As Object, e As EventArgs) Handles txtFilter.TextChanged
chkListBoxSelect.Items.Add("Not Fix Size Menu And ListBox")
chkListBoxSelect.Width = MaxW()
End Sub
Private Function MaxW() As Integer
Dim w As Integer = 0
For Each item As ToolStripItem In Me.Items
If item.Bounds.Width > w Then w += item.Bounds.Width
Next
Return w
End Function
Public Function ValidateTextCellValue(value As String) As Boolean
' Add your validation logic
For Each item In chkListBoxSelect.CheckedItems
If value = item.ToString() Then
Return True
End If
Next
Return False
End Function
End Class
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.