Click here to Skip to main content
14,391,726 members
Rate this:
Please Sign up or sign in to vote.
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 21:46pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

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
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.

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,

DataTable table = child.MyDataTable;
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

You need to create a table on the new window (pass data from child window) - hide the one on the child window.
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100