Hi, So i have 2 form, each has 1 datagridview.
In the FORM1, the datagridview contain some product column and user can input the number of product quantities they want to buy.
if user press the "buy" button, i want it to open FORM2, with datagridview containing the list of the product they buy from datagridview in FORM1.

i have tried to use list, assign the value directly, but no luck

For z As Integer = 0 To dataGridView(0).RowCount - 1  //to identify the row

//assign the value directly
Form2.DataGridView1.Rows(0).Cells(0).Value = dataGridView(0).Rows(z).Cells(0).Value

//use list
Dim list = New List(Of Test)
list.Add(New Test(dataGridView(0).Rows(z).Cells(0).Value, dataGridView(0).Rows(z).Cells(3).Value, dataGridView(0).Rows(z).Cells(1).Value))
Form2.DataGridView1.DataSource = list


//this one does not work as well
Dim n As Integer = Form2.DataGridView1.Rows.Add()
DataGridView1.Rows.Item(n).Cells(0).Value = dataGridView(0).Rows(z).Cells(0).Value
DataGridView1.Rows.Item(n).Cells(1).Value = dataGridView(0).Rows(z).Cells(1).Value
DataGridView1.Rows.Item(n).Cells(1).Value = dataGridView(0).Rows(z).Cells(2).Value

nothing works..
can anyone help?

Dani AI

Generated

Brief summary and key causes found in the examples from and : the goal is to move selected product rows from Form1's DataGridView into Form2's DataGridView. Common problems in the posted snippets are using the default Form2 reference instead of an instance, writing into Rows(0) when no rows exist, mixing manual row operations with a DataSource-bound grid, and simple typos/unqualified references (adding a row to Form2 but assigning values to the local form's DataGridView). Those issues explain why assignments appeared to "do nothing."

A short troubleshooting checklist:

  • Make a real instance: Dim f2 As New Form2 (do not rely on ambiguous default instances).
  • Either use DataGridView.DataSource (recommended) or manipulate Rows directly — do not mix both.
  • When binding, set AutoGenerateColumns = True or create columns with matching DataPropertyName.
  • Skip IsNewRow rows and guard against Nulls when reading cells.
  • Call f2.Show() or f2.ShowDialog() after populating the data source (or populate inside Form2’s constructor).

Recommended, robust pattern (typed list → constructor → BindingList in Form2):

Public Class Product
    Public Property Name As String
    Public Property Price As Decimal
    Public Property Qty As Integer
    Public Sub New(n As String, p As Decimal, q As Integer)
        Name = n : Price = p : Qty = q
    End Sub
End Class

' In Form1: gather items and open Form2
Dim items As New List(Of Product)
For Each r As DataGridViewRow In DataGridView1.Rows
    If Not r.IsNewRow Then
        Dim q As Integer
        Integer.TryParse(Convert.ToString(r.Cells("Qty").Value), q)
        If q > 0 Then items.Add(New Product(Convert.ToString(r.Cells("Name").Value), Convert.ToDecimal(r.Cells("Price").Value), q))
    End If
Next
Dim f2 As New Form2(items)
f2.Show()

Then in Form2:

Public Sub New(products As List(Of Product))
    InitializeComponent()
    DataGridView1.AutoGenerateColumns = True
    DataGridView1.DataSource = New BindingList(Of Product)(products)
End Sub

Notes: runtime column-adding (as showed) is fine for ad-hoc cases, but typed binding is cleaner and less error-prone for product lists. Avoid assigning rows to a grid that is bound to a DataSource; match columns by DataPropertyName when using designer columns.

hi..

here is an example:

i have 2 forms.. on form1 there is a datagridview with 2 columns.. and on form2 there is another one with no column..

see screen shot. it might help

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str1 As String = String.Empty
        Dim str2 As String = String.Empty

        str1 = Me.DataGridView1.Rows(0).Cells(0).Value.ToString()
        str2 = Me.DataGridView1.Rows(0).Cells(1).Value.ToString()

        Dim f2 As New Form2
        f2.DataGridView1.Columns.Add("c1", "c1")
        f2.DataGridView1.Columns.Add("c2", "c2")

        f2.DataGridView1.Rows.Add(str1, str2)
        f2.Show()


    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.DataGridView1.Rows.Add("p1", "200")
        Me.DataGridView1.Rows.Add("p2", "400")
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.