我有一个带有3个值的组合框:File1,File2和File3。我试图根据选择的值来更改文本框FileLocation的值。现在我的代码,值是空白的,不会改变。
public string value1;
public string value2;
public string value3;
private void CooseFileOption()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
if (CPABox.SelectedText == "File1")
{
value1 = ofd.FileName;
}
else if (CPABox.SelectedText == "File2")
{
value2 = ofd.FileName;
}
else if (CPABox.SelectedText == "File3")
{
value3 = ofd.FileName;
}
}
private void CPABox_SelectedIndexChanged(object sender, EventArgs e)
{
if (CPABox.DisplayMember == "File1")
{
FileLocation.Text = value1;
}
else if (CPABox.SelectedText == "File2")
{
FileLocation.Text = value2;
}
else if (CPABox.SelectedText == "File3")
{
FileLocation.Text = value3;
}
}
按下按钮时会调用CooseFileOption()。
答案 0 :(得分:0)
CPABox.SelectedText
我可以使用CPABox.Text