Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't my method work unless called from a button click?
    primarykey
    data
    text
    <p>I posted this question yesterday, but I don't think i gave enough information to get a definate answer. So here it is again with additional code which hopefully will make things clearer.</p> <p>I have a form with a listView, which is populated by calling the showCheckedInFiles() method. The method works perfectly fine when I add a simple button to the form and press it, which calls the method, but when I call the method from elsewhere it will not populate my listview.</p> <p>Please help it's driving me insane. The first method below is called from another class and that is shown underneath this, and I've included the button method as well for reference, as I say, the button works perfectly, but i need to be able to call the method without clicking a button!!:</p> <pre><code>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(); } </code></pre> <p>The method which calls the above:</p> <pre><code>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(); } </code></pre> <p>And this is the actual showCheckedInFiles() method which won't build my listView unless called from the button_3_click method .... which i don't want!</p> <pre><code>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(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload