【发布时间】:2013-03-29 23:45:17
【问题描述】:
我想知道为什么我可以从主类外部的组合框中访问文本。但我无法向其中添加项目。我的组合框的修饰符设置为公共
public class ImageManager : mainFrame // Where my components are located
{
public ImageManager()
{
}
public void getText()
{
Console.WriteLine(comboBox.Text); //Will perfectly retrieve the text from it
}
public void setItem()
{
comboBox.Items.Add("Items"); //Does absolutely nothing and doesn't show error
}
}
感谢您的帮助!
【问题讨论】:
-
如何查看组合框的内容?
-
在我的类 mainFrame 中,我设置了 comboBox.Text = "Test",然后当我从 ImageManager 中的任何位置调用 getText() 时,它在我的控制台中显示“Test”
-
如果您尝试使用 comboBox.Text 获取文本,您将获得组合框中显示的内容。如果未选择任何项目,则在选择项目之前您将一无所获
-
我知道,但为什么我不能因为 X 原因添加新闻项目,但我可以访问文本和其他功能?