繁体   English   中英

该名称在当前上下文中不存在

[英]The name does not exist on the current context

如何获取和使用mainform中的控件名称? 例如,我正在创建一个方法,其中文件将列在ListView上。 我计划在实用程序类中创建此方法,但我收到错误“不包含在当前上下文中”。

public class UtilityClass
{
        private void SearchHeaderFiles( )
        {
            foreach(FileInfo f1 in...)
            {       
        listView.Items.Add(f1.Name);
            }
    }
}
var listView = Application.OpenForms["Form1"].Controls["listView"] As ListView;
if (listView != null)
    listView.Items.Add(f1.Name);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM