Results 1 to 11 of 11

Thread: [RESOLVED] Importing Selected rows in a datagrid

  1. #1

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Resolved [RESOLVED] Importing Selected rows in a datagrid

    Hello everyone,I need help with my program..I just want to know how to link the row i selected to another form? I mean i had already a view on a datagrid coming from my database and i want it to import into another form by just clicking the row i selected. Thanks in advance to those who can help me. Have a nice day!
    Last edited by shyguyjeff; Nov 27th, 2007 at 10:14 PM.

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

    Re: Importing Selected rows in a datagrid

    You let data-binding take care of most of the work. See this thread for the principles. In .NET 1.x you don't have the BindingSource so you have to get your hands a little bit dirtier. For a start, you'll be binding the Datatable directly to the grid instead of via a BindingSource. That also means that you can't do this:
    vb.net Code:
    1. Dim row As DataRow = DirectCast(Me.BindingSource1.Current, DataRowView).Row
    In .NET 1.x you have to use the CurrencyManager directly that gets wrapped in the BindingSource in .NET 2.0:
    vb.net Code:
    1. Dim row As DataRow = DirectCast(DirectCast(Me.BindingContext(myDataTable), CurrencyManager).Current, DataRowView).Row
    I didn't do this sort of thing much before .NET 2.0 so I'm not 100% sure that's correct, but fairly sure.
    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
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: Importing Selected rows in a datagrid

    i have a few question...What does that myDataTable for?do I need to make a table for that?Since I have already data on a datagrid and i want it to just click the value and automatically it will display on a next form..How can I make a BindingSource?The Code appear a lot of error.
    Last edited by shyguyjeff; Jul 31st, 2007 at 12:52 AM.

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

    Re: Importing Selected rows in a datagrid

    Where did the data in the DataGrid come from? A DataTable of course.
    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
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: Importing Selected rows in a datagrid

    what if my data is coming from my database?sorry if i'm so illiterate. The data are coming from my tables of my database. How can I do it?

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

    Re: Importing Selected rows in a datagrid

    You retrieve the data from the database into a DataTable and bind that DataTable to the DataGrid. That's how you're displaying the data in the first place. The code above shows you how to get the DataRow from the DataTable that corresponds to the row selected in the grid. The thread I linked to shows you how to pass that DataRow to a dialogue for editing. When you edit that DataRow in the dialogue the DataGrid will update automatically, which is the whole point of data-binding.
    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

  7. #7

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: Importing Selected rows in a datagrid

    ahhh..i see...so what is the BindingSource stand for?How can I use this code?

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

    Re: Importing Selected rows in a datagrid

    As I clearly stated in my first reply, the BindingSource class is not available in .NET 1.x. The second code snippet is the alternative that you need to use instead of the first specifically for that reason. It's all there in the thread already. Please read carefully.
    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

  9. #9

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: Importing Selected rows in a datagrid

    Okay...Sorry if i keep asking,now i know.Thanks jmcilhinney i will try to follow that steps out there. Have a nice morning. GOd Bless!

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

    Re: Importing Selected rows in a datagrid

    There's nothing wrong with asking lots of questions, but it's important to pay attention to the answers when they're provided.
    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

  11. #11

    Thread Starter
    Hyperactive Member shyguyjeff's Avatar
    Join Date
    Jul 2007
    Location
    City of Durian
    Posts
    289

    Re: Importing Selected rows in a datagrid

    Okie!Dokie!!!Thanks again jmcilhinney...Have a nice day!!!

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