我正在Visual Studio 2010中构建一个小型Visual Basic应用程序,作为一名Web开发人员,我还不是很熟练,所以也许你们可以帮助我!
我只需要帮助从3个列表框中选择所选值并将它们传递给另一个Windows窗体以生成查询并在表中显示查询结果。我特别需要有关如何将值传递给下一个表单的帮助,以及如何让数据网格视图显示动态创建的查询的结果。
提前感谢您的帮助!我是Visual Studio和Visual Basic的菜鸟,请原谅我这是一个非常简单的问题!
更新:以下是我第一张表格中的代码。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Labdataset.Lab' table. You can move, or remove it, as needed.
Me.LabTableAdapter.Fill(Me.Labdataset.Lab)
'TODO: This line of code loads data into the 'Buildingdataset.Building' table. You can move, or remove it, as needed.
Me.BuildingTableAdapter.Fill(Me.Buildingdataset.Building)
'TODO: This line of code loads data into the 'WilfordDataSet.Software' table. You can move, or remove it, as needed.
Me.SoftwareTableAdapter.Fill(Me.WilfordDataSet.Software)
End Sub
Private Sub ListBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabList.SelectedIndexChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.param1 = SoftwareList.SelectedItem
Form2.param2 = BuildingList.SelectedItem
Form2.param3 = LabList.SelectedItem
End Sub
这是我的第二种形式的代码 公共类Form2
Private _param1 As String
Private _param2 As String
Private _param3 As String
Public WriteOnly Property param1 As String
Set(ByVal value As String)
_param1 = value
End Set
End Property
Public WriteOnly Property param2 As String
Set(ByVal value As String)
_param2 = value
End Set
End Property
Public WriteOnly Property param3 As String
Set(ByVal value As String)
_param3 = value
End Set
End Property
答案 0 :(得分:0)
在第二种形式中,更改类的构造函数:
Public Sub New(ByVal param1 As String, ByVal param2 As String, ByVal param3 As String)
InitializeComponent()
MessageBox.Show(param1) 'Just to show that the parameter is correct.
'Should be replaced by methods that process your query.
End Sub
在单击按钮(或任何其他触发器)后应调用的事件处理程序中,您可以传递以下参数:
Private Sub buttonName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myForm = New Form2(ListBox1.SelectedItem, ListBox2.SelectedItem, ListBox3.SelectedItem)
myForm.Show()
End Sub
然后您可以继续处理查询。 这只是一种方法。如果你想要(但有点肮脏的方法),你可以在Form2中声明变量并通过第一个表单访问它。举个例子:
Form2.param1
<强>更新强> 要详细说明第二种方法,在第二种形式中,您可以在类名
之后编写 Private _param1 As String
Private _param2 As String
Private _param3 As String
Public WriteOnly Property param1 As String
Set(ByVal value As String)
_param1 = value
End Set
End Property
'Same with the other parameters...
然后通过
访问第一种形式的参数 Form2.param1 = ListBox1.SelectedItem
'And so on