Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to open new form from a datagridview row?

How to open new form from a datagridview row?

Scheduled Pinned Locked Moved Visual Basic
questioncsharpcssvisual-studiotutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rashar
    wrote on last edited by
    #1

    Hello, Working in visual studio 2005, I have managed to create, setup, and populate a datagridview as follows: Dim ds As DataSet = New DataSet 'FILL DATASET da.Fill(ds, "qryTableReports") ds.Locale = System.Globalization.CultureInfo.CurrentUICulture 'DISPLAY DATASET TO DATAGRIDVIEW1 DataGridView1.DataSource = ds DataGridView1.DataMember = "qryTableReports 'SET COLUMN WIDTH DataGridView1.Columns(0).Width = 25 DataGridView1.Columns(1).Width = 125 DataGridView1.Columns(2).Width = 50 DataGridView1.Columns(3).Width = 50 DataGridView1.Columns(4).Width = 50 DataGridView1.Columns(5).Width = 45 '*** END DATAGRIDVIEW1 SETUP What I want to do now is to be able to select any row from my data grid, and once selected, it will open up a new form with the dataset from the row selected. How can I accomplish this? Is the DataGridView control the best control to use in this case? Thanks in advance.

    H 1 Reply Last reply
    0
    • R Rashar

      Hello, Working in visual studio 2005, I have managed to create, setup, and populate a datagridview as follows: Dim ds As DataSet = New DataSet 'FILL DATASET da.Fill(ds, "qryTableReports") ds.Locale = System.Globalization.CultureInfo.CurrentUICulture 'DISPLAY DATASET TO DATAGRIDVIEW1 DataGridView1.DataSource = ds DataGridView1.DataMember = "qryTableReports 'SET COLUMN WIDTH DataGridView1.Columns(0).Width = 25 DataGridView1.Columns(1).Width = 125 DataGridView1.Columns(2).Width = 50 DataGridView1.Columns(3).Width = 50 DataGridView1.Columns(4).Width = 50 DataGridView1.Columns(5).Width = 45 '*** END DATAGRIDVIEW1 SETUP What I want to do now is to be able to select any row from my data grid, and once selected, it will open up a new form with the dataset from the row selected. How can I accomplish this? Is the DataGridView control the best control to use in this case? Thanks in advance.

      H Offline
      H Offline
      Hansduncan
      wrote on last edited by
      #2

      Is this a case where you want to have like a list of orders and want to open the specific order on a seperate form when you doubleclick the row on the datagridview or something like that?

      R 1 Reply Last reply
      0
      • H Hansduncan

        Is this a case where you want to have like a list of orders and want to open the specific order on a seperate form when you doubleclick the row on the datagridview or something like that?

        R Offline
        R Offline
        Rashar
        wrote on last edited by
        #3

        Yes. That is exactly correct.

        H 1 Reply Last reply
        0
        • R Rashar

          Yes. That is exactly correct.

          H Offline
          H Offline
          Hansduncan
          wrote on last edited by
          #4

          OK....I have just been doing the exact same thing and have it working great. Here is what you need to do: 1) Declare a public parameter as integer on the MDIParent form called something like OrderID or whatever 2) on the doubleclick event on the datagridview you need to: -Get the correct orderID from the datagridview by specifying the correct index (column) value on the currentrow. -Set the orderID parameter = ID found on the datagridview 3) on your table adapter that is called on the load event on the new form you need to pick up the MDIParent.OrderID in a parameterized fill query. Let me know if you need some example syntax? Let me know and I'll post some.

          R 1 Reply Last reply
          0
          • H Hansduncan

            OK....I have just been doing the exact same thing and have it working great. Here is what you need to do: 1) Declare a public parameter as integer on the MDIParent form called something like OrderID or whatever 2) on the doubleclick event on the datagridview you need to: -Get the correct orderID from the datagridview by specifying the correct index (column) value on the currentrow. -Set the orderID parameter = ID found on the datagridview 3) on your table adapter that is called on the load event on the new form you need to pick up the MDIParent.OrderID in a parameterized fill query. Let me know if you need some example syntax? Let me know and I'll post some.

            R Offline
            R Offline
            Rashar
            wrote on last edited by
            #5

            That's great... Could you please post some sample code? I have declared my variable, but it is not passing the id to the other form when I double click on the datagridview row... Thanks for your assistance! -- modified at 12:50 Thursday 10th May, 2007

            H 1 Reply Last reply
            0
            • R Rashar

              That's great... Could you please post some sample code? I have declared my variable, but it is not passing the id to the other form when I double click on the datagridview row... Thanks for your assistance! -- modified at 12:50 Thursday 10th May, 2007

              H Offline
              H Offline
              Hansduncan
              wrote on last edited by
              #6

              Just to clarify....by MDIParent I mean the MDI frame form. I have found that is a stable base to place parameters that need to be shared between forms. here is a syntax example Private Sub CustSalesOpportunityDataGridView_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles CustSalesOpportunityDataGridView.CellDoubleClick MDIParent1.SalesOppToOpen = Me.CustSalesOpportunityDataGridView.Item(0, CustSalesOpportunityDataGridView.CurrentRow.Index).Value Dim SalesOpportunity As New NewSalesOpportunity() SalesOpportunity.Show() End Sub This should work for you too

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups