Saturday, December 20, 2014

C# with Entity, Send Data from Parent Form to Child Form

In Child Form Create an entity object as public and set all form field with that entity property. Like This code:


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
//Declare Purchase Entity Object as Public
        public PurchaseInfo _purchaseInfoObj = new PurchaseInfo();


//Load Purchase Data from Parent Window to Child Form
        public void LoadDataFromDueList()
        {
            txtProductID.Text = this._purchaseInfoObj.ProductId.ToString();
            txtProductName.Text = this._purchaseInfoObj.ProductName;
            txtSupplierName.Text = this._purchaseInfoObj.SupplierName;
            txtTotalPurchaseAmount.Text = this._purchaseInfoObj.TotalPurchaseAmount.ToString();
            txtTotalDue.Text = this._purchaseInfoObj.TotalDue.ToString();
        }


Now in Parent Form, create an Event and write code like this:


1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
//Collect Data from Listview and Send it to child form
        private void MakePaymentContexMenu_Click(object sender, RoutedEventArgs e)
        {
            if (PurchaseDueListView.SelectedIndex > -1)
            {
                SupplierDueCollectionUI supplierDueCollectionUI = new SupplierDueCollectionUI();
                PurchaseInfo purchaseObj = new PurchaseInfo();
                purchaseObj = PurchaseDueListView.SelectedItem as PurchaseInfo; // select and load data from listview

                supplierDueCollectionUI._purchaseInfoObj = purchaseObj; // send it to public entity _purchaseInfoObj
                supplierDueCollectionUI.LoadDataFromDueList(); // Call data load method from child form
                supplierDueCollectionUI.ShowDialog(); // show child form
            }
        }

No comments:

Post a Comment