我在表单加载时将项目添加到菜单中作为下拉项目。
在同一个子目录中我尝试在msgbox中输出menustrip下拉项目,但我得到了所有项目的空白回复。
Private Sub PopulateLoadChildMenu()
msItemLoad.DropDownItems.Clear()
Dim fi As FileInfo
If Directory.GetFiles(_playlistpath).Length > 1 Then
msItemLoad.Enabled = True
End If
For Each fi In _files
msItemLoad.DropDownItems.Add(Path.GetFileNameWithoutExtension(_playlistpath & fi.Name))
Next
For Each MyMenuItem As ToolStripMenuItem In msItemLoad.DropDownItems
txbList.Text = txbList.Text & ", " & MyMenuItem.Tag
Next
End Sub
我在像这样的Sub中使用它
Private Sub FormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fi As FileInfo
msItemLoad.Enabled = False
If Directory.GetFiles(_playlistpath).Length = 1 Then
For Each fi In _files
LoadPlaylist(_playlistpath & fi.Name)
Next
End If
PopulateLoadChildMenu()
End Sub
答案 0 :(得分:1)
查看您的代码,您正在使用Tag
属性(,如果您没有明确设置数据,那么您将不会向TextBox添加任何内容):
txbList.Text = txbList.Text & ", " & MyMenuItem.Tag
您是否有意使用Text
属性
txbList.Text = txbList.Text & ", " & MyMenuItem.Text