我正在使用Visual Studio 2010.我創建了一個使用多種表單的新VB窗體應用程序。將數據從datagrid視圖複製到具有新的datagrid視圖的新表單VB
在這些表單之一(form2)上,我創建了一個基於用戶在form1上選擇的多個項目的datagridview。
最終用戶可以在datagridvew上添加信息,然後他們轉到第三個表單(form3)。在第三種形式中,我想將與form2上的數據網格的前三列相同的信息複製到新的數據網格中。
從列表框中複製的項目在Form1上我使用類似於下面的代碼:
For Each Feature As Object in form1.listbox1.SelectedItems
Me.DatagridView(Col, Row).Value = DirectCast(CustomerFeature, DataRowView)("Feature").ToString()
Row +=1
Next
我想用:
For Each row As DGVRow In form2.DatagridView.Rows
'add information to the new datagrid
Next
我Form3。但是,當我嘗試訪問form2數據時,它不會顯示在intellisense中,也不會讓我手動輸入信息。當我嘗試運行程序時,得到:
「錯誤1引用非共享成員需要對象引用。」
我甚至無法訪問我在該窗體上聲明的公共變量。我應該指出,窗口2將使用稱爲:
Private Sub BTN_Next_Click(sender As System.Object, e As System.EventArgs) Handles BTN_Next.Click
Dim frm_PI_01 As New form2(PIMethod, StartTime, TheUser, TheComputer)
frm_PI_01.ShowDialog()
End Sub
和新方法使用:onload事件期間
Public Sub New(ByVal PIMethod As String, ByVal StartTime As Date, ByVal TheUser As String, ByVal TheComputer As String)
' This call is required by the designer.
InitializeComponent()
PI_Method = PIMethod
Start_Time = StartTime
The_User = TheUser
The_Computer = TheComputer
End Sub
數據網格被填充。