问题描述
我正在运行时创建ToolStripMenuItem的DropDownItems。
I'm creating a ToolStripMenuItem's DropDownItems at runtime.
Me.mnuExtrasSecondaryLCID.DropDownItems.Clear()
Dim iCount As Integer = -1
For Each nLang As clsLanguage In g_LCIDs
If nLang.IsLeader Then
iCount += 1
Dim n As New ToolStripMenuItem
n.Name = "mnuSecondaryLCID" & iCount.ToString()
n.Text = nLang.Title
n.Tag = nLang.LCID
n.Available = True
n.CheckOnClick = True
Me.mnuExtrasSecondaryLCID.DropDownItems.Add(n)
AddHandler n.Click, AddressOf Me.SecondaryLCIDClick
End If
Next
这很好。
当我检查其中一个在运行时使用DropDownItems,同一列表中的任何其他DropDownItems保持选中状态。
我只想检查一次(=最后单击的对象)。
When I then check one of the DropDownItems at runtime, any other DropDownItems in the same "list" stay checked. I would instead like to have only one checked (=the last clicked one).
有没有可以让我自动执行此操作的属性?我需要通过手动取消选中所有其他DropDropItems来对此进行编码吗?
Is there a property that would let me do this automatically, or do I need to code this by unchecking all other DropDropItems manually?
推荐答案
您需要手动对其进行编码。单击子菜单时,取消选中所有其他兄弟姐妹:
You need to code it manually. When clicking on a sub menu, uncheck all other siblings:
For index = 1 To 5
Dim subMenu = New ToolStripMenuItem(index.ToString())
subMenu.CheckOnClick= True
AddHandler subMenu.Click, Sub(obj, arg)
Dim item = DirectCast(obj, ToolStripMenuItem)
For Each sibling In item.Owner.Items.OfType(Of ToolStripMenuItem).Except({obj})
sibling.Checked = False
Next sibling
End Sub
Menu1ToolStripMenuItem.DropDownItems.Add(subMenu)
Next
这篇关于DropDownMenuItem检查应取消选中其他DropDownMenuItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!