Results 1 to 6 of 6

Thread: Passing current record

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    2

    Passing current record

    Hi,
    I am returning to programming after a long absence (last real work done in VB5.0). I'm trying to do a small customer management project. I'm starting off with a DataGridView on one form showing a reduced number of fields. When the customer is selected a second form gives the full details.
    I struggling to find a clean way of passing the selected record to the second form.
    Both forms are using the same dataset.

    Any ideas (I know it's probably too easy, I spent too many with GW and Quick basic).

    Regards

    Luke

  2. #2
    Member cyberM's Avatar
    Join Date
    Mar 2009
    Location
    Croatia , Zagreb
    Posts
    61

    Exclamation Re: Passing current record

    I think that I developed something what you can use.
    Take this code on this adress.
    https://www.planetsourcecode.com/vb/...7492&lngWId=10
    If you satisfied add to reputation





    PhotoResizer GDI+Shape form,shape inside

  3. #3
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    Re: Passing current record

    write a Public Sub New(ByRef dgvi As DataGridViewItem) on your second form with a DataGridViewItem(?) object to pass.
    Then, just pass the selected datagridviewitem from the datagridview, and then extract the appropriate information from the appropriate columns/field/index.
    Then when you want to launch the form, do:
    Dim frm as New Form(DataGridView.SelectedItems(0))

    I may be totally wrong, but I think if you pass it byref it will update the datagridview as well.
    I may be wrong on that tho.
    Last edited by Seraph; Jul 30th, 2010 at 04:06 PM.

    Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7

    SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
    [Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]

    [.NET and MySQL Quick Guide]

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Passing current record

    Follow the CodeBank link in my signature and check out my thread entitled Update Grid Row in Dialogue
    Last edited by jmcilhinney; Jul 31st, 2010 at 12:51 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Passing current record

    Quote Originally Posted by Seraph View Post
    I may be totally wrong, but I think if you pass it byref it will update the datagridview as well.
    I may be wrong on that tho.
    That would only be true if the type of the parameter was a value type. In this case it's a reference type, so you would only need to pass by reference if you intended to assign a new object to the parameter within the method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    2

    Re: Passing current record

    Quote Originally Posted by jmcilhinney View Post
    Follow the CodeBank link in my signature and check out my thread entitled Update Grid Row in Dialogue
    Just the ticket, many thanks for the suggestions.

    Regards

    Luke

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