Jump to content

Transfering Rows Between DataGridViews Across 2 Different Forms In VB.NET

Hi all first time posting in this section of the form. So I'm making this program in visual studio 2013 in VB.NET


Lets say I have 2 forms:


Form1 and Form2 and on Form1 I have DataGridView1 and on form 2 I have DataGridView2


Both data grids have the same columns.


How can I on the click event of a button on Form1 Get all the data from DataGridView1 from the row i'm currently focused/selected on to be transferred into DataGridView2 on Form2 ???


Image of what i'm trying to do.


 UAxbU.png


If anyone can help me out with this one it would be much appreciated. Thanks


Accidentally pooped my pants in the elevator.

I'm taking this shit to a whole new level.

Link to comment
Share on other sites

Link to post
Share on other sites

Not on a computer with visual studio, so I can't quickly look at the class to refresh my memory and test this...but this page might be a good example

 

http://canlu.blogspot.ca/2009/06/copying-datagridviewrow-to-another.html

 

 

Personally I try to avoid using datagridview (although it is a handy class), the flicker annoys me so much :P

 

Anyways, with the website's example you could modify it so it takes in a second argument.

 

 

*Actually I just thought, is your question how do you access the information between forms instead of copying over the dgv? 

If so, a dirty trick which I always recommend but is a quick fix is in lets say form2 code you create a static variable which points to the dgv then when you click transfer in form1 you just grab the static variable...this has the main assumption that only 1 of form2 will ever exist at a given time (for that process)....it is too late and I can't think of anything else

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

A few solutions here. I'd use the event approach myself since the second dialog doesn't have to be modal.

 

http://stackoverflow.com/questions/20551203/how-to-get-values-from-a-dialog-form-in-vb-net

 

I'd use a DataTable object to pass the information between tables using their DataSource property

 

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource(v=vs.110).aspx

main(i){for(;i<101;i++)printf("Fizz\n\0Fizzz\bBuzz\n\0%d\n"+(!(i%5)^!!(i%3)*3)*6,i);}

Link to comment
Share on other sites

Link to post
Share on other sites

are both forms shown at the same time? if not, then in the constructor of form two have it accept a datagrid and from form 1 pass in the datagrid. if they are, then maybe do a static class that both forms reference. no fancy article here, just my two cents on how to do it

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×