Results 1 to 3 of 3

Thread: [Resolved][2.0] Getting DataGridView data

  1. #1

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    [Resolved][2.0] Getting DataGridView data

    Is there any way to "get" the data displayed in the datagridview control?

    The underlying data structure is different for different screens, and I want to use the same data-getting for a handful of datagridviews.

    There does not seem to be a straightforward way to navigate the cells to get their values.
    Last edited by JPicasso; Oct 3rd, 2006 at 07:20 AM.
    Merry Christmas

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

    Re: [2.0] Getting DataGridView data

    The Item property of the DataGridView returns a cell by column name or index and row index. Had you read the help topic for the DataGridView member listing as you should have you'd have seen this description:
    Overloaded. Gets or sets the cell located at the intersection of the specified row and column.
    Once you've got the cell you want you can access its Value or FormattedValue property. Having said that, if your grid is bound then I'd suggest working with the data source rather than the grid is most situations. If you've bound your grid to a BindingSource, as is recommended, then you can get the bound data from that. If the BindingSource is bound to a DataTable then its items are DataRowView objectsw, from which you can get the data directly or from the corresponding DataRow, which is exposed via its Row property.
    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
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    Re: [2.0] Getting DataGridView data

    I actually had been in the help section a couple of times, but never picked up on how to get info back out.

    I stumbled upon the .rows collection which would have been infinatly more apparent to me if I had recalled that C# uses [] instead of () for indexing items.

    It is not a bound data source, and it's a cluster you-know-what to pick out what I need from the Data. Anyways, seems I'm good to go.
    Merry Christmas

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