Results 1 to 4 of 4

Thread: Passing data from DGV to another form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    31

    Passing data from DGV to another form

    Hi,

    I have returned to a project I started a while ago. I have a small members database showing basic info (Title, Forename and Surname) in a data grid view with all data populated from a SQL database.

    I have the dataset populated with all this info as well as other data through the use of relationships/foreign keys (Addresses and Telephone Numbers, etc)

    I have tested the relationships using a simple form which shows the correct addresses, telephones, etc for each user as you navigate through it.

    I now wish to show just the datagridview on form 1 which is read only with the row select set to full row (I have done all this so far). I have also set up a second form which displayes just the relationship data.

    I want to be able to load the second form (with the address and telephone number data, etc) when the row is double clicked by the user. ie - if row 15 is double clicked on, then the second form should load the address and telephone number data for record 15.

    I am having no luck right now and hope all has been explained ok?

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    31

    Re: Passing data from DGV to another form

    Right after a little more research I have now placed this code into the DGV:
    Code:
        Private Sub UsersDataGridView_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles UsersDataGridView.CellContentDoubleClick
            Dim UserRow As DataGridViewRow = UsersDataGridView.Rows(e.RowIndex)
            Using dialogue As New UserEdit(UserRow)
                dialogue.ShowDialog()
            End Using
        End Sub
    Assuming I want to pass DataGridViewRow into the form UserEdit, what code would need to be put into the second form to allow the above to work?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    31

    Re: Passing data from DGV to another form

    Anyone know where to look for the code needed in Form2 to accept the input from Form1? I have been trawling the net for hours now and am no further forward

  4. #4
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Re: Passing data from DGV to another form

    Put this code in the form receiving the DataGridViewRow:

    vb Code:
    1. Public Sub New(ByVal row As DataGridViewRow)
    2.  
    3.      Me.InitializeComponent()
    4.  
    5.      ' You can then use the object row as necessary
    6.  
    7. End Sub
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width