C#如果listbox.selecteditems.contains值则 [英] C# if listbox.selecteditems.contains value then

查看:294
本文介绍了C#如果listbox.selecteditems.contains值则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我的comboBox在列表框中选择某个项目后即可显示.
我有以下代码:

Hi I''m trying to get my comboBox to become visible once a certain item is selected in my listbox.
I have this code:

If(listBox.SelectedItems.Contains("Tea"))
{
    ComboBox.Visible = true;
}



这不起作用...还有其他想法吗?



This isn''t working... Any other ideas?

推荐答案

您好,
将代码移动到click事件将起作用.

Hello,
Move the code to click event it will work.

private void listBox1_Click(object sender, EventArgs e)
{
 if (listBox1.SelectedItems.Contains("Tea"))
   comboBox1.Visible = true;
}



谢谢!!!



Thanks!!!


对不起...当我运行程序并选择Tea时,comboBox变得不可见.
但是,如果我将代码更改为
If(listBox.Items.Contains("Tea"))
{
ComboBox.visible = true;
}
然后我选择茶,出现comboBox.但是即使我没有选择茶也会出现.
Sorry... When I run the program, and Tea is selected, the comboBox does not become visible.
However, if I change the code to
If(listBox.Items.Contains("Tea"))
{
ComboBox.visible = true;
}
And I select tea, the comboBox appears. But it appears even if I do not select tea.


这篇关于C#如果listbox.selecteditems.contains值则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆