Click here to Skip to main content
15,914,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm creating my windows application and I need to update my supplier's datagridview and transfer the selected rows to another form for editing

help me please :( how will I code this one using vb.net? using ado.net?
Posted

When you have bound your DataGridView to an Object you can pass the bound Object to another form like this (answer copied from a question I answered a while back):
Here is the original question: How to pass the Value one form to another form in windows form[^]

To pass Objects between Forms you can follow one of these approaches:
One is using a Property on one of your Forms.
C#
MyForm frm = new MyForm();
// It is possible to set MyValue at any point in your code, as long as you have a reference to an instance of MyForm.
frm.MyValue = "some value";
frm.Show();

Another is passing it to the constructor.
C#
public partial class MyForm : Form
{
   private String _myValue;
   public Form1(String myValue)
   {
      InitializeComponent();
      _myValue = myValue;
      // Possibly use myValue here.
   }
   // Do stuff with _myValue here.
}
Usage would look like this:
C#
MyForm frm = new MyForm("some value");
frm.Show();

Another approach could be to use a Method...
C#
public partial class MyForm : Form
{
   private String _myValue;
   public void SetValue(String myValue)
   {
      _myValue = myValue;
     // Possibly do stuff with myValue here.
   }
   // Or use _myValue here.
}
Usage:
C#
MyForm frm = new MyForm();
frm.Show();
// Once again, you can use this anywhere in your code, as long as you have a reference to the instance of MyForm.
frm.SetValue("some value");


So now you got your data in another Form, all you need to do is handle it there, edit it etc. and update it in the Form it originally came from.
You can also do this with unbound data, except the updating of your original grid might be some extra work.

The code is in C#, but any convertor[^] can convert it to VB for you :)

Hope it helps :)
 
Share this answer
 
v2
Comments
lyn10 20-Nov-11 5:38am    
Thank you :)
Sander Rossel 20-Nov-11 6:44am    
No problem. Don't forget to vote/accept the answer that helped you :)
RaisKazi 20-Nov-11 8:50am    
Correct and comprehensive. 5ed.
Sander Rossel 20-Nov-11 8:59am    
Thanks Rais :)
VB
Dim x as String = Me.DatagridView1.Rows(1).Cells("ColumnName").value

;)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900