mardi 20 janvier 2015

populate a combobox with values of selected checkboxes on a previous form?

I have a form which contain a set of checkboxes. What I want to do, is when the user select some checkboxes and then click on a button, a new form will appear which contain a combobox that holds the values/texts of previously selected checkboxes.


enter image description here


In the above form, here what happens when the user clicks next :



private void btnNext_Click(object sender, EventArgs e)
{
Step3 stp3 = new Step3();

foreach (Control c in this.Controls) {
if (c is CheckBox) {
stp3.addChosenModule(c.Text);
}
}

stp3.Show();
this.Hide();
}


And here what the form named Step3 contains in it's class:



public partial class Step3 : Form
{
public List<string> chosenModules = new List<string>();
public void addChosenModule(string moduleName) {
chosenModules.Add(moduleName);
}

public Step3()
{
InitializeComponent();
}

private void Step3_Load(object sender, EventArgs e)
{
foreach (string itm in chosenModules) {
cbModules.Items.Add(itm);
}
}
}


Now, after clicking on Next, the new form shows up but the combobox is still empty ? enter image description here





Aucun commentaire:

Enregistrer un commentaire