Refreshing Datagrid from another form

ahbenshaut

Well-known member
Joined
Oct 29, 2004
Messages
62
Location
Alaska
Programming Experience
5-10
Good Day.
I have an application that has 2 forms. On the first form, there is a datagrid and a button. When the button is clicked, another form is opend so the user can add data to the datagrid. My question is, how can I refresh the datagrid on the First Page once the user clicks the "Add" button on the second form?

Thanks for the help
 
My first question is why are you using a seperate form for input when the user can simply enter a new row in the DataGrid itself? If you really want to use the second form the solution has nothing to do with the DataGrid whatsoever. You should call NewRow on the DataTable that is the grid's DataSource and pass the DataRow returned to the constructor of the second form. You would then display the second form by calling ShowDialog. If the user OKs the values in the new record you would set the form's DialogResult property to OK, or if they Cancel you would set it to Cancel. That DialogResult value will then be returned by ShowDialog. If it is OK you would then retrieve the (now populated) DataRow from the second form via a public property and simply Add it to the DataTable. Because the table is bound to the grid the new row will be displayed automatically.
 
whew

Ok..I figured it out and it was way easier than I thought. All i did was instantiate form1 on form2 so I can call the function on form1 that calls the LoadDataGrid function. So now by the time form2 is closed the datagrid on form1 has been refreshed. :)

I agree, I wanted to use the Datagrid as the data entry point but I have to add several values that the user won't/cant.
 
Back
Top