Adding into listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have created one windows application form (form1) in vc# . there is one
listbox in that form. i have anothere form( form2). From form2 i have give
one button. on the click event of that button i have to load items from the
listbox which is in form1. how can i do this? plz give solution for this

thanking u
 
Hi Lkr,

You can create in the form 2 class a event and a method to handle the event
like this:

public event EventHandler form2buttonclick;

public virtual void OnForm2ButtonClick(object sender, EventArgs e)
{
if(form2buttonclick!=null)
{
form2buttonclick(sender,e);
}
}

Then add this piece of code in the onclick button in the form2

OnForm2ButtonClick(sender, e);


And once you have this, go to the form1, in the OnInit method you have to
have something like this:
Form form2=new form2();

add this line:
form2.OnForm2ButtonClick +=new EventHandler(Form2ButtonClick)

private void Form2ButtonClick(object sender, EventArgs e)
{
MessageBox.Show("The user Clicks in the button of the Form2");
}

Hope this helps.
Kind Regards.
Josema.
 
hi
my question is i created a windows form in c# ie Form1in that form1i
created a listbox.and also created another form Form2. i have a link in form1
to form2. in form2 i created a button. on the click event of the button i am
compiling one java code and i want tht compilation output to be loaded into
the listbox which is in form1.
 
Back
Top