Communicating Between 2 Forms..

  • Thread starter Thread starter Serdar C.
  • Start date Start date
S

Serdar C.

hello again, i have another question... i am writing a program with 2
windows forms...

first form have a search button and several text buttons to list the data
loaded from an sql database

second form just have a listbox that shows the search results in the
listbox..
i want to let user select from the second form's listbox and show the
results from the first form. how can i "post" te selected items name to the
first form without creating another form? the only way i find is like this:

first form:

public void listitems(string selecteditem)
{
dataview.rowfilter = "username = '" +selecteditem +"'";
}

and in the second form:

private void listBox1_DoubleClick(object sender, System.EventArgs e)

{

Form1 f = new Form1();

f.list(listBox1.SelectedItem.ToString());

f.Show();

}



but that makes my program show several "form1" ' s in my program and thats
something i really dont want to happen.. so is there a way to "post"
variables between forms like asp.net do?



p.s: i cant write replies from outlook express. so i thank you from here
for spending your time to respond and helping. have a good day.
 
Hi,

Instead of creating public function in form1 create a public function in
form2. When user selects the value from the list box in the 2nd form just
hide the form2 and than call that public function from form1 and dispose the
second form(if needed)

I think this would help :)
 
Back
Top