简体   繁体   English

如果选择 combobox 中的最后一项,如何使文本框可见 c#

[英]How to make a textbox visible if last item in a combobox is selected c#

I have combobox9,textBox4 and textBox15 in a winform.我在 winform 中有 combobox9、textBox4 和 textBox15。 By default, textBox15 is hidden.默认情况下,textBox15 是隐藏的。

What i'm trying to do.我正在尝试做的事情。

If textbox4 backcolor is red and the last item in combobox9 is selected, then show textbox15.如果 textbox4 的背景颜色为红色,并且选择了 combobox9 中的最后一项,则显示 textbox15。

         if (comboBox9.SelectedIndex == comboBox9.Items.Count - 1  && textBox4.BackColor == Color.Red) ;

            {
                textBox15.Visible = true;

                textBox15.BackColor = Color.Red;
            }

            
            else
            {

                textBox15.Visible = false;
            }

No errors, it just doesn't work as expected.没有错误,它只是没有按预期工作。 It keeps the textbox hidden even when the conditions are satisfied.即使满足条件,它也会隐藏文本框。 Any leads?有什么线索吗?

You should put all your code in your SelectedIndexChanged event of your combobox您应该将所有代码放在 combobox 的SelectedIndexChanged事件中

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if(comboBox1.SelectedIndex == comboBox1.Items.Count - 1)
    {
        label1.Visible = true;
    }
    else
    {
        label1.Visible = false;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#从文本框中更新选定的ComboBox项目名称 - C# Updating Selected ComboBox Item Name from Textbox 如何根据 ComboBox 中选择的项目使 TextBox 只读? - How to make a TextBox read-only based on the item selected in the ComboBox? 在C#中,如何使用Combobox和Textbox选择索引 - In C#, How to use Selected Index with Combobox and Textbox C#如何使Menustrip中的一项成为默认选择? 如何显示从“选定的菜单”到文本框中的选定项目 - C# How to make one item from Menustrip be default selected? How to display the selected items from Menustrip Selected to a textbox 如何显示所选 WPF ComboBox 项目 C# 中的内容 - How to display content from selected WPF ComboBox item C# 如何在组合框 C# 中获取所选项目的 id - How to get id of selected item in combobox C# 如何在C#Windows窗体中设置ComboBox的选定项? - How to set Selected item of ComboBox in C# Windows Forms? 如何显示“默认”所选项目-组合框C#WPF - How to display “default” selected item - Combobox C# WPF 如何检查是否从 C# 中的组合框中选择了项目 - how to check if item is selected from a comboBox in C# c#xml函数,用于检查字符串是否等于xml属性,以将选定的组合框项添加到文本框 - c# xml function to check whether a string is equal to a xml attribute, to add selected combobox item to textbox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM