Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Passing Checkbox.Text if checked
 

Passing Checkbox.Text if checked

im entering data into textboxes. If the checkbox is checked i wanna pass the data in the textbox and the checkbox.text to form2. Here i need to show what was entered as a review stage and submit back to form1 whether or not to submit the data or edit it again.

Form1 Code

namespace bankaccount

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void depositSubmit_Click(object sender, EventArgs e)

{

Form2 formreview = new Form2(dateTimePicker1.Text, check_checkBox1.Text, check_deposit1.Text);

formreview.Show();

}

}

}

Form2 Code

namespace bankaccount

{

public partial class Form2 : Form

{

public Form2(string strTextBox, string check1, string check2)

{

InitializeComponent();

label1.Text = strTextBox;

label2.Text = check1;

label3.Text = check2;

}

}

}

jgurgen  Thursday, June 08, 2006 11:58 PM

You have no choice but to use 10 if statements, unless you can pass your strings as a collection ( that is, if they all go to the same place and you can just pass an array of strings as one parameter ). In this case, it can also be a constructor argument. Then you can use foreach on the controls collection or another collection that holds your check boxes, and check each one, adding it's text if it is checked.

cgraus  Friday, June 09, 2006 11:07 PM

To communicate back to form1 when form2 is modeless, you need to set up a delegate.  Or you can use a modal form (ShowDialog instead of Show ) and put a property on form2 which you can check when it closes.

 I should add that if the strings are being passed conditionally, they should probably be properties you set, rather than constructor arguments.

 

cgraus  Friday, June 09, 2006 12:26 AM

ok makes sense, but how do i check the to see if the check boxes are checked and then pass checkbox.text? i dont want 10 if or switch statements.

can i do something like:

private checkstatus()

{ check status on all checkboxes, whatever is true return checkbox.text

}

jgurgen  Friday, June 09, 2006 2:20 PM

You have no choice but to use 10 if statements, unless you can pass your strings as a collection ( that is, if they all go to the same place and you can just pass an array of strings as one parameter ). In this case, it can also be a constructor argument. Then you can use foreach on the controls collection or another collection that holds your check boxes, and check each one, adding it's text if it is checked.

cgraus  Friday, June 09, 2006 11:07 PM

You can use google to search for other answers

Custom Search

More Threads

• Detecting DesignTime vs Runtime issues
• Problem with adding child controls
• Query regarding restricting modification of properties....
• Cannot cast MyControl to MyControl in designer
• Designer keeps writing bad code for datagridview after I fix it
• which Control Can I Use
• CommandText Property Editor
• Wizard Form - Component Designer
• How do I capture the MouseDown event at Design time
• Scaling for a Designer surface