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?


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)

    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
Attachments Untitled.png 12.4 KB
This question has already been answered. Start a new discussion instead.