为什么我的方法不起作用?

Dae*_*lus 0 c#

我有一个带有a的表单,listView通过调用该showCheckedInFiles()方法填充.当我向表单添加一个简单的按钮并按下它时,该方法完全正常,调用该方法,但是当我从其他地方调用该方法时,它将不会填充我的listview.

请帮助它让我疯狂.下面的第一个方法是从另一个类调用的,它显示在下面,我已经包含了按钮方法以供参考,正如我所说,按钮工作完美,但我需要能够调用方法而不需要单击一个按钮!!:

public void openProject(string projectname)
{
    projectName = projectname;
    string userDir = CSDBpath + projectname + "\\checkedOUT\\" + userName;
    if (!Directory.Exists(userDir)) //Does the user's directory exist, if not, create it
    {
        Directory.CreateDirectory(userDir);
    }
    showCheckedInFiles();
 }

 private void button3_Click(object sender, EventArgs e)
 {
    showCheckedInFiles();
 }
Run Code Online (Sandbox Code Playgroud)

调用上述方法:

private void buttonOpenProject_Click(object sender, EventArgs e)
{
     ListView.SelectedListViewItemCollection mySelectedItems;
     mySelectedItems = listView1.SelectedItems;
     Form1 mainform = new Form1();
     string myProject = "";

     foreach (ListViewItem item in mySelectedItems)
     {
         myProject = item.Text;
     }

     mainform.openProject(myProject);
     //mainform.showCheckedInFiles();
     this.Close();
 }
Run Code Online (Sandbox Code Playgroud)

wRA*_*RAR 5

buttonOpenProject_Click您创建一个新的隐藏实例时,Form1该实例与已经显示的显然已存在的实例无关.