0

What the program is doing is allowing employees to load and run a program file to a machine on the factory floor. The application launches to a default directory on the network that houses many different programs, they select which one they're running and run it.

What I've done is create an admin form so that we can go out to any machine and change the directory they are accessing (more options to change will be added).

So it launches say for "C:\Files\". Later I go into the admin form and change it to "D:\Files\". I can't seem to then pass that new directory listing to the main form.

MainForm

private void Main_Load(object sender, EventArgs e)
{
    txtsaveprogram.Visible = false;
    this.Size = new Size(444, 579);
    MachineID();

    string[] files = System.IO.Directory.GetFiles(tempvar, "*.NC");

    foreach (string file in files)
    {
        string fileName = Path.GetFileName(file);               
        cmbfiles.Items.Add(fileName);       
    }
}

Currently tempvar = @"\\hq1\MFG\DNC\Grinders\PR";

AdminForm

namespace MachineConfig
{
    public partial class adminconfig : Form
    {
        public string programdefaultpath { get; set; }

        public adminconfig()
        {
            InitializeComponent();
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        public void adminconfig_Load(object sender, EventArgs e)
        {
            string[] dir = System.IO.Directory.GetDirectories(@"\\hq1\MFG\DNC\");
            foreach (string filedir in dir)
            {
                string dirpath = Path.GetFileName(filedir);
                comboBox1.Items.Add(dirpath);
            }
        }

        private void btndirectory_Click(object sender, EventArgs e)
        {
            string[] subdir = System.IO.Directory.GetDirectories(@"\\hq1\MFG\DNC\" + comboBox1.Text);
            foreach (string filesub in subdir)
            {
                string subdirpath = Path.GetFileName(filesub);

                comboBox2.Items.Add(subdirpath);
            }
        }

        private void adminconfig_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {           
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
    }
}

How do I have these newly selected directories now be the directory they're in on the mainform so the dropdown box now displays the new contents of the newly chosen directory?

Der Kommissar
  • 5,848
  • 1
  • 29
  • 43
Lee
  • 95
  • 2
  • 9
  • 1
    There are two (easy, obvious) ways to handle this: 1) pass the directory from the admin from back to the `mainform`; 2) pass the entire directory structure from the admin form back to the `mainform`. Both are easy: create a **public property or field** that is either a string (for the directory) or a list of strings (for the structure) on the admin form that contains whichever data you are passing back to the `mainform`, then after your `adminForm.Show()` (which I don't see here), read the data from that public **property or field** and use it in the `mainform`. – Der Kommissar May 19 '15 at 14:09
  • I was overly complicating things for some reason, it hasn't been a good day. Your comment though EBrown woke me up :) its working now. Thanks for the kick in the pants. – Lee May 19 '15 at 14:33
  • Not a problem, often times the simplest things give us all the largest bit of trouble. – Der Kommissar May 19 '15 at 14:38

0 Answers0