Saturday, December 20, 2014

C# Entity, Load Data from Child window to Parent window

In child window create an event and use code like this:

1
2
3
4
5
6
7
8
//Send data to Parent form
        private void CustomerInfoListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (CustomerInfoListView.SelectedIndex > -1)
            {
                this.DialogResult = true;
            }
        }

Now in Parent window create a button event for show child window and get data. Use code like this:


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
//Get data from child window and set it to parent window
        private void btnGet_Click(object sender, RoutedEventArgs e)
        {
            CustomerInfoUI customerUI = new CustomerInfoUI(); //Child window object

            if (customerUI.ShowDialog() == true) // Set condition for show child window and do some operation
            {
                CustomerInfo customerObj = new CustomerInfo(); //Child window entity object
                customerObj = customerUI.CustomerInfoListView.SelectedItem as CustomerInfo; //Load child window listview data to entity
                txtCustomerName.Text = customerObj.CustomerName; // set data to parent window text field
                txtCustomerId.Text = customerObj.Id.ToString();// set data to parent window text field
                this._customerInfoObj.Id = customerObj.Id; // set child window ID to parent window ID

                customerUI.Close(); //Close child window
            }
        }


No comments:

Post a Comment