• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Visual Basic, Open Form based on row value

Hi Everyone,

I have an interface that looks at related rows from different tables. Basically, it has a form/sub-form relationship.

The interface allows them to select a single row from a Datagridview. What I want, is for a second form to open based on the row selection in the first form. It would open the same row in a second form that looks at just that table. (The primary key is: GoalRowID). Also, the row in the second form contains more columns for the table.

Here is some of my incomplete code:
    Private Sub EditRowButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditRowButton.Click

        Dim RecordIDString As String

        If  DataGridView1.SelectedRows.Count > 1 Then
            MessageBox.Show("You can only select one row at a time")
        Else
            Form2.ShowDialog()

        End If
    End Sub

Open in new window

0
jonsuns7
Asked:
jonsuns7
1 Solution
 
CodeCruiserCommented:
In the else part, you need to get the primary key ID from selected row using code like below

Dim ID as integer = Datagridview1.SelectedRows(0).Cells("GoalRowID").Value

Then

Form2.GoalRowID = ID
Form2.ShowDialog()


You will need to declare GoalRowID as a public property on Form2 so you can pass it from form1. Then in form2 load, use that ID to load data from DB.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now