0

The title of my question seems simpler then my problem really is. What I am doing is trying to put a string into my textbox, but it won't go in. I'm doing this by passing the string from one class to another and then another. Sort of trickling down the ladder so to speak. The string starts here:

public static void FilePath(string fileName)
{
    string fn = fileName;
    PicForm.FileName(fn);
}

fileName is being pulled from a saveFileDialog by way of FilePath(sd.FileName). It then moves to PicForm.FileName(), which looks like this:

public static void FileName(string fileName)
{
    string fn = fileName;
    AddAtt aa = new AddAtt(Form1.con);
    aa.AddScan(fn);            
}

From there it is sent to aa.AddScan(), which looks like this:

public void AddScan(string fileName)
{
    textBox7.Text = fileName;
}

Clearly this is were the string is to be entered into the textbox, but it doesn't. Now I've added MessageBoxes to check to make sure that the sting is making it to here and that the textBox7.Text is being set to the string(fileName) properly. And the MessageBoxes show that the code works. But the textbox says differently. I've also tried a different way of using AddScan(). I added it to another button that uses an openFileDialog. And that looks like this:

private void button3_Click(object sender, EventArgs e)
{
    string Chosen_File = "";
    openFileDialog1.InitialDirectory = "C:";
    openFileDialog1.FileName = "";

    if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
    {
        MessageBox.Show("Operation Cancelled");
    }
    else
    {
        Chosen_File = openFileDialog1.FileName;
        //textBox7.Text = Chosen_File;
        AddScan(Chosen_File);
    }
}

Now when I call AddScan() from that click event, the textBox7 displays the text properly. My question is why does it work one way but not the other. It seems to me that the code should work. Any help would be great.

Ian R. O'Brien
  • 6,682
  • 9
  • 45
  • 73
woods
  • 243
  • 4
  • 10
  • 20
  • 2
    Have you tried stepping through the code in Debug mode? – System Down Dec 14 '12 at 17:52
  • The issue with that is that the code requires a scanner to be attached to the computer to run. I don't have one on my pc and the one that does, doesn't have vs installed. I've been switching between the two. Programming on one pc and testing on the other. Its a bit of a pain in the ass. – woods Dec 14 '12 at 17:59
  • 3
    Could it be that you are creating a new instance of AddAtt when you need to use an _existing_ instance? – PhoenixReborn Dec 14 '12 at 18:00
  • But as for debug. since I'm unable to, I've used MessageBox.Show(textBox7.Text) after the textBox7.Text = fileName part of the code. And the MessageBox returns the proper string. But the textBox wont display it. I don't get it. – woods Dec 14 '12 at 18:01
  • @PhoenixReborn, I think your probably right on that. – woods Dec 14 '12 at 18:03
  • @PhoenixReborn, you were completely right. Thank you so much. I would have sat here for a while before I'd even thought of that. – woods Dec 14 '12 at 18:10
  • @PhoenixReborn: why don't you post your comment as an answer so user1339005 can accept it? – comecme Dec 14 '12 at 19:23

1 Answers1

1

In your FileName function, you are creating a new instance of your AddAtt class when you really need to use an exisiting instance of that class to set the text in the Textbox.

PhoenixReborn
  • 153
  • 1
  • 2
  • 5