我有一个带有一些Datagridviews的表单,其中填充了来自不同数据库的数据(截图1) enter image description here 当我右键单击弹出一个新表单时,我想要填充所选行中的所有数据(截图2) enter image description here 在我的代码中,我硬编码了数字1376以查看它是否有效。如果我用ValuePass替换数字1376,它将无法工作。所以我需要一种方法以某种方式传递该值。它对一段有效的字符串做了同样的事情,但它似乎不适用于该值。
所以这是我到目前为止在我的第一个表格
中得到的Public Class Relatie_beheer
Public SQL As New SQLControl
Dim value As Object
Private Sub dvgRelaties_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles dgvRelaties.CellClick
If (e.RowIndex = -1 Or e.ColumnIndex = -1) Then Return
' No matter which cell is clicked, put the data from the field in the relatie_nr column in the variable value
Dim x As Integer
x = e.ColumnIndex + (3 - e.ColumnIndex)
value = dgvRelaties.Rows(e.RowIndex).Cells(x).Value
End Sub
Private Sub WijzigenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles WijzigenToolStripMenuItem.Click
Dim Obj As New RelatieNieuw With {
.StringPass = "Wijzigen"
}
Dim ValObj As New RelatieNieuw With {
.ValuePass = value
}
Obj.ShowDialog()
End Sub
在我的第二个表格中
Public Class RelatieNieuw
Public SQL As New SQLControl
Public Property StringPass As String
Public Property ValuePass As String
Private Sub RelatieNieuw_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label2.Text = StringPass + " Relatie"
Select Case StringPass
Case "Toevoegen"
' Open new window and create a new private key number
Case "Wijzigen"
' Open new window and retrieve relatie fields to change
SQL.AddParam("@item", 1376)
SQL.ExecQuery("SELECT * FROM relatie WHERE Relatie_nr = @item;")
txtzoeknaam.Text = SQL.DBDT.Rows(0)(1).ToString
Case "Verwijder"
' Open new window and retrieve relatie fields to delete
Case Else
MsgBox("Option not defined " + StringPass)
End Select
End Sub
答案 0 :(得分:1)
您正在创建2个不同的RelatieNieuw对象,而该对象应该是1个具有2个参数的对象:
Dim Obj As New RelatieNieuw With {
.StringPass = "Wijzigen",
.ValuePass = value
}
'是的:忘了逗号
答案 1 :(得分:0)
我通过以下方式自行更改:
在第一种形式中,我将代码更改为:
Dim value As Object
Private Sub WijzigenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles WijzigenToolStripMenuItem.Click
Dim Obj As New RelatieNieuw("Wijzigen", value)
Obj.ShowDialog()
End Sub
我的第二种形式现在看起来像这样:
Public Class RelatieNieuw
Public SQL As New SQLControl
Public Property StringPass As String
Dim ValuePass As String
Public Sub New(ByVal pstr As String, ByVal value As String)
' This call Is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
StringPass = pstr
ValuePass = value
End Sub
而不是1376我有ValuePass
似乎现在正在工作。