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

Recommended Answers

All 2 Replies

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());
                }
            }

Awesome....... it's work

Thx alot!!

GaBack

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.