我有一个列表框,在一个单独的类中我试图访问列表框的选定值,但它说它不能被访问,因为它不是公共的。我在访问标签时也遇到了同样的问题。
public dataCollector(string i)
{
string tag = i;
}
public string dataCollector()
{
Form1 f = new Form1();
string workingDirectory = Directory.GetCurrentDirectory();
var xmlFile = XDocument.Load(workingDirectory + @"\modules.xml");
var name = from d in xmlFile.Descendants("Name")
where d.Value == (String)f.selectionBox.SelectedItem
select d.Parent.Element(tag).Value;
foreach (var item in name)
{
f.moduleName.Text = item.ToString();
}
}