1

I have one form with a few Datagridviews which are populated with data from different databases (screenshot 1) enter image description here When I right click a new form pops up which I want to populate with all the data from the row that is selected (screenshot 2) enter image description here In my code I hard coded the number 1376 to see if it works. If I replace the number 1376 with ValuePass it won't work. So I need a way to pass that value somehow. It did the same thing for a piece of string which works but it does not seem to work for the value.

So this is what I got so far in my first Form

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

And in my second Form

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

2 Answers 2

1

You are creating 2 different RelatieNieuw-objects, while that should be 1 object with 2 params:

Dim Obj As New RelatieNieuw With {
    .StringPass = "Wijzigen",
    .ValuePass = value
}

'yeah: forgot the comma

1
  • If I do that I get an error. It expects an } after "Wijzigen" Sep 21, 2017 at 13:40
0

I changed it myself in the following way:

In the first form I changed the code to this:

    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

And my second form looks like this now:

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

and instead of the 1376 i have ValuePass

Seems to work now.

1
  • Yes, that is basically the same as the solution I mentioned. I forgot a comma in the above code. I edited the original post.
    – Veeke
    Sep 21, 2017 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.