0

I have two Forms (Form "Sales Order" and Form "Insert Detail Document"). In Form "Sales Order" I have insert some values into several objects, please refer to the following screenshot:

enter image description here

After insert some values for header document, next I want to insert detail document by clicked on Add button in Form "Sales Order".

Form "Insert Detail Document" will be shown after that button was clicked, please refer to the following screenshot:

enter image description here

I have insert all values in all objects in "Insert Detail Document". I need all values in this Form will be shown in Data Grid View in Form "Sales Order" by clicking on Add button this Form. So, Form will be shown like the following screenshot:

enter image description here

Does anyone knows how to provide this condition ? Thanks.

HariEko
  • 395
  • 1
  • 11
  • Take a look to [this](https://stackoverflow.com/questions/1559770/send-values-from-one-form-to-another-form) post. It may help. – dcg Feb 22 '18 at 03:58
  • thanks for your references, but it still doesn't correspond to my goal – HariEko Feb 22 '18 at 06:32

2 Answers2

1
        public class Product_List {
            public string Branch { get; set; }
            public string InvetoryID { get; set; }
            public string Warehouse { get; set; }
            public string Quantity { get; set; }
            public string Unit { get; set; }

        }
     public partial class Insert_Detail : Form
        {
            public DataTable Grid_Product = new DataTable();
            List<Product_List> productlist = new List<Product_List>();
             private void Add_Click(object sender, EventArgs e)
            {
                pcmn.cmn_DT.Clear();
                Grid_Product.Clear();            


                        productlist.Add(new Product_List
                        {
                            Branch = txt_Branch.Text,
                            InvetoryID =  ddlInvetoryID.SelectedValue.ToString(),
                            Warehouse = ddlWarehouse.SelectedValue.ToString(),
                            Quantity = txt_Quantity.Text,
                            Unit = txt_Unit.Text,

                        });


                Grid_Product = ToDataTable(productlist);
                                this.Close();
            }
        }


         public partial class SalesOrder : Form
        {
         public void AddItem_Click(object sender, EventArgs e)
            {
        POS_ITEM_Details popup = new POS_ITEM_Details();

                                popup.ShowDialog();
                                foreach (DataRow row in popup.Grid_Product.Rows)
                                {
        SalesOrder_Grid.Rows.Add(row["Branch"].ToString(), row["InvetoryID"].ToString(),row["Warehouse"].ToString(),..);
        }
        }

 public DataTable ToDataTable<T>(List<T> items)
        {
            DataTable dataTable = new DataTable(typeof(T).Name);
            //Get all the properties
            PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {
                //Setting column names as Property names
                dataTable.Columns.Add(prop.Name);
            }
            foreach (T item in items)
            {
                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {
                    //inserting property values to datatable rows
                    values[i] = Props[i].GetValue(item, null);
                }
                dataTable.Rows.Add(values);
            }
            //put a breakpoint here and check datatable
            return dataTable;
        }
Alex
  • 28
  • 4
0

In such cases i prefer to use an event. You could register the events in your main form. On the add button, you could inform the grid window. You could transport your data in some easy to use EventArgs.

This way allows you to easily change your form by just expand your EventArgs

Flocke
  • 41
  • 1
  • 8