【发布时间】:2013-10-14 07:30:42
【问题描述】:
对于我的 windows 窗体应用程序,我尝试从 listBox 中检索选定的字符串,我希望它与设置的字符串进行比较,以便在比较返回 true 的情况下,我可以将下一个 listBox 设置为具有特定的,选择相关的值。
namespace PhysCalc
{
public class Selectors
{
public static string[] topicContents = new string[] { "MECHANICS", "THEORY_OF_RELATIVITY" };
public static string[] VarItemsMechanics = new string[] { "Test", "Wavelength" };
public static void SetVarBox()
{
PhysCalc.Topic.DataSource = topicContents;
if PhysCalc.Topic.Items[PhysCalc.Topic.SelectedIndex].ToString() == "MECHANICS")
{
PhysCalc.Var.DataSource = VarItemsMechanics;
}
}
}
}
但不知何故,当我在列表框中选择“MECHANICS”时(在上面名为“主题”的代码中),第二个列表框(上面名为“Var”)只是保持空白
任何帮助将不胜感激
【问题讨论】:
-
VarItemsMechanics是什么? -
抱歉没有发布;它是一个数组,应该设置为“Var”列表框的数据源
-
您确定您的
VarItemsMechanics不为空吗? -
是的,我是,这里是确切的代码: public static string[] topicContents = new string[] { "MECHANICS", "THEORY_OF_RELATIVITY" }; public static string[] VarItemsMechanics = new string[] { "Test", "Wavelength" };
-
您发布的代码中没有错误,所以只有那几行代码我们无法辨别太多,我们只能猜测。
标签: c# string winforms listbox compare