[英]Pass all rows from a DataGridView on one form to another vb.net
So i am trying to pass all rows from a DataGridView on a Button Click from one form to another. 所以我试图将DataGridView上的所有行从一个按钮单击传递到另一种形式。 Which is from grd_order in frm_1.vb to grd_invoice in frm_2.vb
从frm_1.vb中的grd_order到frm_2.vb中的grd_invoice
This is as far as i can go since i am stil new to vb.net 因为我是vb.net的新手,所以这是我所能做的
frm_1.vb frm_1.vb
Private Sub btn_purchase_Click(sender As System.Object, e As System.EventArgs) Handles btn_purchase.Click
Dim newForm As New frm_2
newForm.AllRows = grd_order.DataSource
'what should i put here because the above line is wrong
newForm.Show()
End Sub
frm_2.vb frm_2.vb
Public Class frm_2
Public Property AllRows As DataGridViewSelectedRowCollection
'I know that DataGridViewSelectedRowCollection is used for the specific row but what about all rows?
Private Sub frm_2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'grd_invoice.DataSource = PassText
'what should i put here
End Sub
End Class
try this 尝试这个
Private Sub btn_purchase_Click(sender As System.Object, e As System.EventArgs) Handles btn_purchase.Click
Dim newForm As New frm_2
For Each col As DataGridViewColumn In grd_order.Columns
newform.grd_invoice.Columns.Add(col)
Next
For Each row as DataGridViewRow in grd_order.rows
newForm.grd_invoice.Rows.Add(row)
next
newForm.Show()
End Sub
hope this helps. 希望这可以帮助。
The most simple way would be passing the DataSource
of your first DataGridView
to second one. 最简单的方法是将第一个
DataGridView
的DataSource
传递给第二个。
Public Class frm_customer_invoice_a153834
Public Property Data As Object
Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.grd_invoice.DataSource = Data
End Sub
End Class
You can also define the Data
property as DataTable
and pass the data table that you have on your first form, to the second form. 您还可以将
Data
属性定义为DataTable
,并将您在第一个表单上拥有的数据表传递给第二个表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.