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. DataGridView - Sorting [modified]

DataGridView - Sorting [modified]

Scheduled Pinned Locked Moved C#
databasealgorithmsquestionannouncement
1 Posts 1 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.
  • M Offline
    M Offline
    myNameIsRon
    wrote on last edited by
    #1

    Hi, I have Form app that includes a DataGridView control (bound to DataTable). The user can sort the columns by clicking the column headers. If the user has clicked the Date header (to sort the column), the code below fails to update all rows in the DataGridView (and Database). The list is fairly large (few hundred), so I can only guess that when a certain number of rows are updated (via - row.Cells["Col_ItemAddedDate"].Value = newItemDate;) a resort occurs that mucks up the foreach loop? If I don't update the DGV cell, the loop works fine to update database. foreach (DataGridViewRow row in dataGridView1.SelectedRows) { OleDbCommand myCommand = new OleDbCommand("UPDATE Products SET ItemAddedDate=? WHERE ItemID=?", myConnection); myCommand.Parameters.Add("@ItemAddedDate", OleDbType.Date).Value = newItemDate; myCommand.Parameters.Add("@ItemID", OleDbType.BigInt).Value = row.Cells["ItemID"].Value; // execute the command myCommand.ExecuteNonQuery(); // THIS CODE CAUSES THE LOOP TO FAIL (if the Col_ItemAddedDate column header is clicked to sort) // Some of the rows are updated, but some do not (both Database UPDATE and the DGV cell update will fail) row.Cells["Col_ItemAddedDate"].Value = newItemDate; } Ron

    modified on Monday, December 29, 2008 6:40 PM

    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