Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I have Wpf Application , from the Main Window when i clicked button a new child window is shown , some actions happens in this child window ,then i want when a button in child window is clicked , a data table is moved to the Main Window any one can help me in doing that,..?
===============
my question about how can i pass the data from the child window to the main window when button clicked
thanks
Posted
Updated 20-Apr-11 20:46pm
v2

Hi,

you can use event method to pass values from Child to Parent.

Suppose We have two classes names Parent and Child. Then create an event in Child class like

public delegate ValueChangedHandler(DataTable DT);
public event ValueChangedHandler ValueChanged;


Now raise this event from Button event click

if(ValueChanged!=null)
{
   //DT: Suppose it is the desired object to return
   ValueChanged(DT);
}


Now come to Parent class, here you have to handle this event like

Child objChild=new Child();
objChild.ValueChanged += new ValueChangedHandler(objChild_ValueChanged);
objChild.Show();


New method will create with the name "objChild_ValueChanged" like

void objChild_ValueChanged(DataTable DT)
{
  //TODO: Now you can use this value which in coming from Child class.
}


regards
Ankit
 
Share this answer
 
v2
Create public property/member in the child window. Say, MyDataTable is a public property in the Child Window.

You must have used the following (similar) code to open the Child Window.

C#
MyChildWindow child = new MyChildWindow();
child.Show();


Now assign the data table value to MyDataTable property from the ChildWindow. You can access it from the Parent Window like,

C#
DataTable table = child.MyDataTable;
 
Share this answer
 
You need to create a table on the new window (pass data from child window) - hide the one on the child window.
 
Share this answer
 
Comments
Yasser El Shazly 21-Apr-11 2:45am    
my question about how can i pass the data from the child window to the main window when button clicked

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