【发布时间】:2013-07-17 11:59:32
【问题描述】:
我有一个小问题给我带来了一些问题,我相信这并不难,但对我来说现在是。
我有两个类,一个主类和我的 winform 类。
foreach (EA.Element theElement in myPackage.Elements)
{
foreach (EA.Attribute theAttribute in theElement.Attributes)
{
attribute = theAttribute.Name.ToString();
value = theAttribute.Default.ToString();
AddAttributeValue(attribute, value);
}
}
我在这里获取值并尝试通过这种方法将它们写入数据网格:
private void AddAttributeValue(string attribute, string value)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = attribute;
dataGridView1.Rows[n].Cells[1].Value = value;
}
但是编译器告诉我,AddAttributeValue 不在当前上下文中,我无法调用它。我得到了我想要的值,但不能将它们传递给表单。我知道这听起来微不足道,但我就是不明白。
【问题讨论】:
-
标准 OOP 问题,您需要对表单对象的引用。并将方法公开。
-
我一开始就公开了,这不是问题,也不是解决方案,肯定是不同的东西,但还是谢谢你。
标签: c# winforms visual-studio-2010 datagridview