How to get and use the control name from the mainform? For example is, I am creating a method in which files will be listed on a ListView. And I plan to create this method in a utility class but I get an error "does not contain on the current context".
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.