我是vb.net中的新手。我有一个datagridview,显示交货编号,日期和供应商。现在,我希望管理员查看每个交付到另一个表单的详细信息。我只想知道如何获取所选行的id,然后将能够显示所选ID的等效数据。感谢。
这是我的交货表格代码。
Private Sub dgvDeliveryReport_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDeliveryReport.CellContentDoubleClick
If e.RowIndex < 0 Then Exit Sub
Dim id As Int32 = dgvDeliveryReport.CurrentRow.Cells(0).Value
Dim viewDelivery As New frmDeliveryFormReport
frmDeliveryFormReport.Show()
End Sub
答案 0 :(得分:0)
尝试。
Dim newFrmName as new yourForm
For each row as DataGridViewRow in SampleGrid
if row.selected = true then
Dim whatValueYouWant as string = row.cells("ID").value.toString()
if newFrmName.NameOfTextBoxInForm.Text <> vbEmpty Then
'NameOfTextBoxInForm is textbox that existing in yourform
newFrmName.NameOfTextBoxInForm.text = ", " & whatValueYouWant
Else
newFrmName.NameOfTextBoxInForm.text = whatValueYouWant
End If
End IF
Next
newFrmName.Show()
答案 1 :(得分:0)
在frmDeliveryFormReport
课程中添加新字段以存储当前行:
private _currentDeliveryReportRow as DataGridViewRow
寻找构造函数:
Public Sub New frmDeliveryFormReport()
...
End Sub
(如果你找不到它,只需继续下一步)。
更改/添加构造函数,使其获取DataGridViewRow
参数并存储给定的行:
Public Sub New frmDeliveryFormReport(deliveryReportRow as DataGridViewRow)
_currentDeliveryReportRow = deliveryReportRow
End Sub
调整现有dgvDeliveryReport_CellContentDoubleClick
以调用新构造函数:
Private Sub dgvDeliveryReport_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDeliveryReport.CellContentDoubleClick
If e.RowIndex < 0 Then Exit Sub
Dim viewDelivery As New frmDeliveryFormReport(dgvDeliveryReport.CurrentRow)
frmDeliveryFormReport.Show()
End Sub
然后,您可以通过
访问frmDeliveryFormReport中DeliveryReportRow的所有列_currentDeliveryReportRow.Cells(<CellIndex>)
有关此主题的其他信息:
Passing variables between windows forms in VS 2010
VB.Net Passing values to another form
http://www.dreamincode.net/forums/topic/332553-passing-data-between-forms/