Visual Basic, Open Form based on row value

Posted on 2012-09-21
Medium Priority
Last Modified: 2012-09-24
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")

        End If
    End Sub

Open in new window

Question by:jonsuns7
1 Comment
LVL 83

Accepted Solution

CodeCruiser earned 2000 total points
ID: 38422981
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


Form2.GoalRowID = ID

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.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question