0

I have two issues with a method I am calling.

I have frmForm1 & frmForm2.

frmForm1 contains a method as below...

public frmForm1()
{
    InitializeComponent();
}

//This method receives the prog name and WOtype names from frmForm2
int progID;
string programName;

public void GetIDandValue(string valName, int ID, string addWOValue)
{
    if (valName == "progName")
    {
        progID = ID;
        programName = addWOValue;
    }
}

private void button1_Click(object sender, EventArgs e)
{
    frmForm2 loadfrmForm2 = new frmForm2();
    loadfrmForm2.Show();
}

Then from frmForm2 (which is opened from a btn click on frmForm1), I am trying to send values back to the method on frmForm1 so they can be used.

private void button1_Click(object sender, EventArgs e)
{
    selectedValueID = Int32.Parse(comboBox1.ValueMember);
    selectedValueName = comboBox1.DisplayMember;

    string valToSend = "progName";

    frmForm1.GetIDandValue(valToSend, selectedValueID, selectedValueName);

    this.Hide();
}

And finally, here's how combobox1 is being initialised...

comboBox1.DisplayMember = dsAddWO.Tables[0].Columns[1].ToString();
comboBox1.ValueMember = dsAddWO.Tables[0].Columns[0].ToString();
comboBox1.DataSource = dsAddWO.Tables[0];
comboBox1.Enabled = true;

Problem 1) combobox1 ValueMember and Displaymember are returning the column headers as values when i try to populate the variables (although the correct data is actually displaying in the combobox on the form).

Problem 2) I cant seem to call the GetIDandValue method from frmForm2, intellisense just doesnt see it.

No doubt im doing something incredibly stupid. Can anyone enlighten me?

AGB
  • 2,230
  • 1
  • 14
  • 21
SiC99
  • 37
  • 3
  • Thanks for the answers, I resolved it by changing the program logic and doing away with the second form. – SiC99 May 15 '16 at 22:11

2 Answers2

0

You can pass the progID and programName to the constructor of frmForm2

Slugart
  • 4,535
  • 24
  • 32
  • Thanks, but I need to pass the values back to frmForm1 which is already open - am I correct in thinking the constructor approach would require creating a new instance of frmForm1? If so I lose all current values already held in frmForm1 - maybe I should have made it clear that I need to pass this to an open form. Also, any idea on why I the combo box display/value members are holding column headers? – SiC99 May 15 '16 at 12:43
0

Dose those codes are coded on form2 ?

private void button1_Click(object sender, EventArgs e) { selectedValueID = Int32.Parse(comboBox1.ValueMember); selectedValueName = comboBox1.DisplayMember; string valToSend = "progName"; frmForm1.GetIDandValue(valToSend, selectedValueID, selectedValueName); this.Hide(); }

If so, u'd better get a structor of from1, it seems u don't. like u did with form2: frmForm2 loadfrmForm2 = new frmForm2(); and then call to the method frmForm1.GetIDandValue(valToSend, selectedValueID, selectedValueName); Totally Like This From1 frmForm1 =new From1();frmForm1.GetIDandValue(valToSend, selectedValueID, selectedValueName);

Noel
  • 1
  • 3
  • I'm sorry, I cant really understand your writing. The first bit of code is contained in form1 – SiC99 May 15 '16 at 16:13