在选择其他ComboBox C#之后用值填充ComboBox时出现问题

时间:2019-02-12 19:33:08

标签: c# winforms

在用户在第一个组合框中选择一个值之后,尝试将值放入另一个组合框中时遇到问题

private void ClassComboBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ClassComboBox.Items.ToString().Equals("Warrior"))
        {
            RoleComboBox.Items.Add("Tank");
            RoleComboBox.Items.Add("DPS");

        }


    }

到目前为止,这是我所拥有的,因为一旦玩家选择了自己的战士等级,他们的角色就只能是以下值之一。问题是当我运行它时,我的RoleComboBox中没有值。如果有人可以帮助,那就太好了。谢谢

1 个答案:

答案 0 :(得分:2)

private void ClassComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ClassComboBox.SelectedItem.ToString() == "Warrior")
    {
        RoleComboBox.Items.Add("Tank");
        RoleComboBox.Items.Add("DPS");

    }


}

这可能有用吗?我正在用手机,所以无法在Visual Studio中进行测试