Results 1 to 6 of 6

Thread: [2005] data from datagridview to new form?!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    27

    [2005] data from datagridview to new form?!

    Hi, all!

    I want to make an application where user can click on datagridview row and new form opens. New form will contain textboxes where all data will be loaded... first step, of course, is making dblclick event on table, and open new form... I have made it trough so far... what should I do next?

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

    Re: [2005] data from datagridview to new form?!

    You should show us your code. This problem should be broken down into three distinct parts:

    1. Handle the DoubleClick event of the grid.
    2. Get the data for the current row in the grid.
    3. Open a form and pass data to it.

    These are three separate, unrelated problems and you should treat them as such. Once you've solved all three of those problems you can simply put them together and you've solved your original problem. That's called "divide and conquer". Can you do those three things? If not, which parts are you having an issue with? Remember, you should tackle each sub-problem first without worrying about how it fits into the bigger picture.
    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    27

    Re: [2005] data from datagridview to new form?!

    I just dont have any idea how to pass data to another form... thats where the problem is

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

    Re: [2005] data from datagridview to new form?!

    You should read the "Forms in VB.NET" tutorial in my signature.

    Forms are objects like any other in VB.NET. If you wanted to pass data to some other object what would you do? You'd set a property or call a method and pass a parameter. Forms are objects so you do exactly the same thing to pass data to a form. You can pass a DataTable, a DataRow or individual field values. Because it's your form it's up to you to write these properties or methods that you will call. That's not a problem though. You write properties and methods all the time and this is no different. Note that class constructors are methods too, and that's a good place to pass data to a form that every instance will need.
    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

    Thread Starter
    Junior Member
    Join Date
    Aug 2006
    Posts
    27

    Re: [2005] data from datagridview to new form?!

    so now I can pass data from one textbox to another, thats kinda cool... question - how can I take data from row.. For example - if I have an table with columns "Date, time, action", how can I load them into textboxes so, that textbox1 would display "date" cell value, textbox2 - time value, etc?

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

    Re: [2005] data from datagridview to new form?!

    You should pass the bound row and get your data from that. If you have bound a DataTable through a BindingSource, as I recommend that you do, then the BindingSource.Current property will retrun a reference to a DataRowView object for the current row. To get the value from a particular column you simply do this:
    VB Code:
    1. Dim row As DataRowView = DirectCast(myBindingSource.Current, DataRowView)
    2.  
    3. MessageBox.Show(row("ColumnName"))
    That's one of the reasons that it'sa good idea to use a BindingSource: because it makes getting at the bound data much easier. When the user selects a row in the grid you can get the bound data from the BindingSource using the first line above without worrying about indexes or anything like that. You'd then pass that DataRowView to your second form and it would get the individual fields as done in the second line above. If the user makes changes you simply assign the new values to the fields again and your grid AND bound DataTable will update automatically. If anyone tells you that data-binding is a bad thing then they don't know how to use it properly.
    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

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