Pass data between forms for a selected row in DataGridView
I´m coding in C# and Windows Forms.
I´m doing a project where you can add people and then add orders to them. I have four forms:
- In form1, you can add a person's name, number and so on.
- In form2, you can edit a person.
- In form3, you can see order history for the selected person.
- In form4, you can add orders and see them in the order history (form3).
Form1 has textbox where you can add some information and then all of them will be showed in a dataGridView. And if you select a row, you can then go to form3 and see the order history.
My problems are, if I select a person and wanted to add an order, then the order should come to every person that i have added. So, I only want to ad开发者_Python百科d an order in form3 to the selected person in form1.
Let me make it clear:
If i select a person in form1 that i have added and pressed the button 'Order History' then, I would come to form3. When I´m inside form3, I can add a new order. When i have added a new order it will be showed in form3 (order history). Not only for the selected person, but for all of the people who are in my DataGridView.What can i do?
do not couple your forms so much, do not access to UI controls of one form from another, this will kill everything if you replace a grid with a listview or a dropdown...
just make public method in a form and call it from the other form so only inside that method you will retrieve selected items or whatever data...
精彩评论