Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all.

I have 2 Form in my project Form1 and Form2

I have to get items in a Listbox in Form2 when initializing in Form1.

Here is the code in Form1:

C#
private void OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new XmppClientConnection.RosterHandler(OnRosterItem), new object[] { this, item });
                return;
            }
            if (item.Subscription == SubscriptionType.both)
            {
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (item.Jid.ToString() == listBox1.Items[i].ToString())
                    {
                        listBox1.Items.Remove(item.Jid);
                    }
                }
                listBox1.Items.Add(item.Jid.ToString());
            }
        }



This Listbox1 is in Form2 how to get the items there.

Thank you
Posted
Comments
DamithSL 2-May-14 3:22am    
are you create Form2 from Form1? can you show the code related to initializing Form2 ?
Member 10579673 2-May-14 3:46am    
No i have a button on Form1 to open Form2 and the listbox1 is in Form2.My problem is that if i create a new connection in Form2 it will be overloaded.so i created the connection in Form1 but the list must be generated in Listbox1 in Form2.

Maybe this code project article can help you.

Passing Data Between Forms

JAFC
 
Share this answer
 
if form2 is open as a pop up then u can direct assess form1.listbox1.selecteditem and loop through it and populate the form2 listbox.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900