0
Answer

Hoe do you maintain the Datatable across the forms?

Ask a question
sumit

sumit

14y
3.9k
1

Hello Gurus,
I am relatively new to VB.NET windows forms. I have a question for you guys.
I have two Windows forms. First form (Form1.vb) have a grid and a Button (called Search). The grid is initially empty. When the user click the Search button, another form will open (Form2.vb), which also have a grid which is pre-populated and a button (called Select). The user will select some rows from grid from Form2.vb and click select button, then it should bring back the rows to form1.vb grid. User may again click the search button and go to form2.vb and select some more rows and those rows should get APPENDED to the existing rows on form1.vb grid.
I have done this and its also working but I am not sure if that a good solution. What I have done is I have declared a DataTable called gdt in global.vb in my application. Then when the user selects the rows from form2.vb and click select, I populate the gdt datatable with the selected rows. and on form1.vb, I just do datagridview1.datasource = gdt.
I am not sure if declaring a datatable at a global level is a good idea. Any thoughts/help/suggestion will be helpful.
Thanks
Sumit