Hi

I'm totally new and this is my first post. If i do any wrong pls forgive me :D

My problem is: First i made form2 in form1:

Form2 form2 = new Form2();
form2.show();

After that i have a checkboxlist in form2.
Now i want to get which i check in the checkboxlist will display on listbox in form1 when i click on button to close form2

ps: This is the code i did in form2

    private void btnVorurStadfesta_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < (chbVorur.Items.Count-1); i++)
        {
            foreach (var item in VorurList)
            {
                if (chbVorur.GetItemCheckState(i) == CheckState.Checked)
                {
                    chbVorur.SetItemCheckState(i,CheckState.Indeterminate);
                }
            }
        }
        BinaryFormatter fs = new BinaryFormatter();
        FileStream output = new FileStream(@"C:\Users\user\Destop\loka.dat", FileMode.Open, FileAccess.Write);
        fs.Serialize(output, VorurList);
        output.Close();
        this.Close();
    }

GaBack

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I made this for you. I am not so experienced programmer, but this works. I tested.

//Declare variable in form1 class
public static ArrayList listArray=new ArrayList();

//Click button to show form 2 - method in form1 class
private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            listArray.Clear();
            form2.ShowDialog();
            //after closing form 2 add items from ArrayList to ListBox
            for (int i = 0; i < listArray.Count; i++)
            {
                listBox1.Items.Add(listArray[i].ToString());
            }
        }

//Code for transferring values
// I used FormClosing event/method for form2
//Transfer Values from checkedlisbox 'chb' to public ArrayList listArray

            for (int i = 0; i < chb.Items.Count; i++)
            {
                if (chb.GetItemChecked(i))
                {
                    Form1.listArray.Add(chb.Items[i].ToString());
                }
            }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.