昨日この質問を投稿しましたが、明確な回答を得るのに十分な情報を提供できなかったと思います。そのため、ここでも追加のコードを使用して、物事をより明確にすることを願っています。
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();
}
上記を呼び出すメソッド:
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();
}
そして、これは実際の showCheckedInFiles() メソッドで、button_3_click メソッドから呼び出されない限り、listView をビルドしません .... これは望ましくありません!
public void showCheckedInFiles() // ListView1 - load the DMs into the listView to create the list
{
listView1.Items.Clear(); // this clears the list of files each time the method is called preventing the list from being duplicated over and over - (refreshes it) !!
string[] checkedINfileList = Directory.GetFiles(CSDBpath + projectName, "*.sgm", SearchOption.AllDirectories); //JAKE I'VE ADDED THE EXTRA ARGUMENTS HERE and removed \\CheckedIN, MAY NEED TO DELETE FROM .SGM ETC
foreach (string file in checkedINfileList)
{
ListViewItem itemName = list1.getName(file); // get this information from the files in the array
long itemSize = list1.getSize(file);
DateTime itemModified = list1.getDate(file);
listView1.Items.Add(itemName); // now use that information to populate the listview
itemName.SubItems.Add(itemSize.ToString() + " Kb");
itemName.SubItems.Add(itemModified.ToString());
// readFromCSV(); //Reads the data to the CSV file using the method
// // StringBuilder sb = ReadingListView(); //writes the data to the CSV file
// // fileWrite.writeToCSV(sb);
showStatus(itemName);
}
showMyCheckedOutFiles();
}