Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getting data back the order as it appears in datagridview

getting data back the order as it appears in datagridview

Scheduled Pinned Locked Moved C#
questionhelpannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gericooper
    wrote on last edited by
    #1

    hi, It would be quite an important thing for the user to get the data back in the order as it appears in the datagridview. rows of data are got from other gridviews (user clicks on other grids' rows and rows are copied to the gridview in question) so... no problem until user adds rows from the beginning(0 rows), and then saves his data, but: if user add rows the deletes rows then adds the same row again and save, the newly added row appears the first, however it was added the last. (BindingSource.Endedit is called each operation) any idea?? I also tried the BindingSource.ResetBindings() method, but that didn't helped. for saving tableadapter.update() is called. thx, g

    D 1 Reply Last reply
    0
    • G gericooper

      hi, It would be quite an important thing for the user to get the data back in the order as it appears in the datagridview. rows of data are got from other gridviews (user clicks on other grids' rows and rows are copied to the gridview in question) so... no problem until user adds rows from the beginning(0 rows), and then saves his data, but: if user add rows the deletes rows then adds the same row again and save, the newly added row appears the first, however it was added the last. (BindingSource.Endedit is called each operation) any idea?? I also tried the BindingSource.ResetBindings() method, but that didn't helped. for saving tableadapter.update() is called. thx, g

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Did you know that databases do not care about the order of records in a table?? Unless told otherwise with a ORDER BY clause, a SELECT statement can return records in any order. About the only way to accomplish this would be to give each record in the table an index number specifying which row in the view it is in. When you write the data back out to the database, you'd have to include this view order number with the data and store it in it's own column in the table. When you retrieve the data again, you'd have to specify and ORDER BY clause on that view order column in the SELECT statement, thereby guaranteeing that you get a table sorted in the order the user last saw it.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      G 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Did you know that databases do not care about the order of records in a table?? Unless told otherwise with a ORDER BY clause, a SELECT statement can return records in any order. About the only way to accomplish this would be to give each record in the table an index number specifying which row in the view it is in. When you write the data back out to the database, you'd have to include this view order number with the data and store it in it's own column in the table. When you retrieve the data again, you'd have to specify and ORDER BY clause on that view order column in the SELECT statement, thereby guaranteeing that you get a table sorted in the order the user last saw it.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        G Offline
        G Offline
        gericooper
        wrote on last edited by
        #3

        thx that gives me the idea.... now only 1 question left.for the accomplish of the above is it OK to have an [int-increment 1 ] identity (primary key)column for this?

        D 1 Reply Last reply
        0
        • G gericooper

          thx that gives me the idea.... now only 1 question left.for the accomplish of the above is it OK to have an [int-increment 1 ] identity (primary key)column for this?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Each record is going to need it's own identity, yes, but it's useless in the row order because your users can rearrange the rows. You'd actually need BOTH colums, one for an ID key and the other for the row position in the view.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          G 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Each record is going to need it's own identity, yes, but it's useless in the row order because your users can rearrange the rows. You'd actually need BOTH colums, one for an ID key and the other for the row position in the view.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            G Offline
            G Offline
            gericooper
            wrote on last edited by
            #5

            Thanks Dave problem solved

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups