Is it possible to use CheckBox[] within a Delegate to pass the data to and from a second form?
Please go easy on me as I am way to old to be a student and am self taught (kinda). I just have some spefic needs that I am working on.
This is what I have done:
Without the CheckBox[] it works fine sending strings back and forth between forms. When I add the CheckBox[] it goes on vacation!
Main Form
public delegate void EditItemDelegate(string txt1, string txt2, string txt3, CheckBox[] checkBoxes);
Click Event to Open Second Form ()
{
// Pass Data to Second Form
frm_MyGlobalDrawObjects frm = new frm_MyGlobalDrawObjects();
frm.textBox1.Text = "Test 1";
frm.textBox2.Text = "Test 2";
frm.textBox3.Text = "Test 3";
// CheckBox[] is created elsewhere
// The number of CheckBoxes created will be dynamic depending on other conditions
// This works to create the CheckBoxes on the Second Form
// and adds the CheckBoxes to a GroupBox
foreach(KeyValuePair<int, CheckBox[]> kvp in ChartsForGlobal)
{
foreach (CheckBox ck in kvp.Value)
{
CheckBox cb = new CheckBox();
cb.Name = ck.Name;
cb.Location = ck.Location;
cb.Text = ck.Text;
cb.Checked = ck.Checked;
frm.gbx_GlobalChartSelection.Controls.Add(cb);
}
}
frm.EditItemCallback = new EditItemDelegate(this.EditItemCallbackFn);
frm.Show();
}
private void EditItemCallbackFn(string txt1, string txt2, string txt3, CheckBox[] checkBoxes)
{
Print(String.Format(" Updated TextBox 1 {0}", txt1 ));
Print(String.Format(" Updated TextBox 2 {0}", txt2 ));
Print(String.Format(" Updated TextBox 3 {0}", txt3 ));
// Clueless begins here. Not able to get CheckBox[] from Second Form.
// Need to Loop through the CheckBox[]
// If Checked. do something
// else do something different
}
Second Form
public EditItemDelegate EditItemCallback;
public frm_MyGlobalDrawObjects()
{
InitializeComponent();
}
private void frm_btn_Save_Click(object sender, EventArgs e)
{
// Does NOT like the way I have CheckBox[] here.
EditItemCallback(textBox1.Text, textBox2.Text, textBox3.Text, CheckBox[] checkBoxes );
this.Close();
}
Many, many thanks for anyone that can offer some suggestions.