简体   繁体   English

ComboBox.SelectedItem不再相关吗?

[英]ComboBox.SelectedItem no longer relevant?

Good Afternoon, 下午好,

I am using a ComboBox in visual studio to determine whether a user can use a text field below it on a form. 我在Visual Studio中使用ComboBox来确定用户是否可以在表单上使用其下方的文本字段。

The Combobox "ReasonBox" is bound to a datasource and sql query that selects the allowed "Reasons" to choose from. 组合框“ ReasonBox”绑定到数据源和sql查询,该查询选择允许的“ Reasons”以供选择。

Before I had the dynamic selections I was using: 在进行动态选择之前,我使用的是:

private void ReasonBox_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ReasonBox.SelectedValue != null)   `
        if (ReasonBox.SelectedItem.ToString() == "Other")
        {
             { ReasonTextBox.Enabled = true; }
             { ReasonTextBox.BackColor = Color.White; }
        }
}

to enable writing to the TextBox when "Other" was selected. 选择“其他”时启用写入文本框的功能。

Unfortuantely now I am unable to figure out how to make this happen with my databound ReasonBox. 不幸的是,现在我无法弄清楚如何通过数据绑定的ReasonBox做到这一点。 Any Ideas? 有任何想法吗?

Edit: Thanks for the help guys, I think i've found the reason: 编辑:感谢您的帮助,我想我已经找到了原因:

ReasonBox_SelectedIndexChanged

Appears to not be triggering when I change the selection. 更改选择时似乎未触发。 I'll investigate further in the morning :) 我会在早上进一步调查:)

try this 尝试这个

ReasonBox.Text == "Other"

Text property gets or sets the text associated with this control. Text属性获取或设置与此控件关联的文本。

Try 尝试

"ReasonBox.Text" == "Other"

OR 要么

ReasonBox.Items[ReasonBox.SelectedIndex].ToString() == "Other"

Insted of 插入

ReasonBox.SelectedItem.ToString() == "Other"

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM