【发布时间】:2015-01-21 16:14:39
【问题描述】:
我有一个组合框,当该项目被选中时,它与其他形式的 button.text 相同,button.text 更改为用户在文本框中键入的名称。但是如果 item 与 button.text 不同,我想隐藏它,这样用户就无法选择或看到它。
cafetariacombo 是组合框
Form3.cafetaria2.Text 是我要更改的按钮
If cafetariacombo.SelectedItem = "cafetaria2" Then
Form3.cafetaria2.Text = TextBox1.Text
My.Settings.cafetaria2guardar = Form3.cafetaria2.Text
My.Settings.Save()
end if
我用它来命名按钮,我只需要知道我是否可以隐藏组合框项。
请帮帮我:)
用一些代码更新
我自己在组合框中插入了项目列表。 我解决了我之前的问题,但现在我需要在离开表单时保存组合框项的状态。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If cafetariacombo.SelectedItem <> Form3.cafetaria1.Text Then
cafetariacombo.Items.Remove("cafetaria1")
End If
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox2.SelectedItem = Form3.cafetaria1.Text Then
Form3.cafetaria1.Text = "cafetaria1"
My.Settings.cafetaria1guardar = Form3.cafetaria1.Text
My.Settings.Save()
adicionarproduto.cafetariacombo.Items.Add("cafetaria1")
end if
end sub
当我从组合框中删除项目时,我在 form1 中,当我再次添加项目时,我在 form2 中。
当我离开form1时,只需要保存带有已删除项目的组合框。
【问题讨论】:
-
您“隐藏”了一个组合框项目,不将其包含在其 Items 集合中。唯一的办法。
-
您可以使用
cafeteriacombo.Items.Remove("cafeteria2")删除“cafeteria2”项。