简体   繁体   中英

Windows Form C# code to transfer data from one form into a Data Grid on another form

I have a dashboard where the left side tabs (as shown below) represent different department and requests. The goal is for someone from "Machining" to go into their tab to use that form and someone from "Assembly" use that tab. I want both entered data to go into a single "submission log" form I can access to see all open requests. Click this to see the Dashboard

On form 1 I have a panel of different data aspects. All I need to know is how to get the data from this form and populate it into my submission data grid. Form1 . SubmissionForm

Any help would be greatly appreciated.

This a possible solution not knowing your data source type and without too much input in the question.

//On the dashboard pass the datasource to the  overloaded constructor (created below)
var form1=new Form1(YourDataSource)
form1.Show();


//On Form1, declare a variable
public ObjectTypeDataSource {get;set;}

//On Form1, create an overloaded constructor
public Form1(ObjectTypeDataSource source)
{
this.ObjectTypeDataSource=source;
}

//At this point, you are up to populate the grid view with this.ObjectTypeDataSource. Maybe Form1.Load() or Form1.Activate();

Note: check the form lifecycle to know where to populate the gridview, more details here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM