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. Programatic Edit of a DataGridView

Programatic Edit of a DataGridView

Scheduled Pinned Locked Moved C#
helpquestion
3 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.
  • P Offline
    P Offline
    Pualee
    wrote on last edited by
    #1

    Hi, If a user edits a value on a DataGridView, the DataTable under its DataSource recognizes the change when calling DataTable.GetChanges() However, if I edit a value programatically on the DataGridView, the DataTable.GetChanges() returns a NullReferenceException as if no change took place. I know it saved to the DataTable, because I can look at it and see the updated value. Is there something else I need to call on the DataGridView after programatically updating it to make the changes noticable on the DataTable? Some type of commit method that is automatically called when a user edits? Right now I am bypassing the error by updating directly on the DataTable, but I know the DataGridView.Rows is a much smaller collection to loop for changing than the DataTable.Rows (due to filtering already in place). Should I worry about this efficiency issue at all? Thanks, Pualee

    P 1 Reply Last reply
    0
    • P Pualee

      Hi, If a user edits a value on a DataGridView, the DataTable under its DataSource recognizes the change when calling DataTable.GetChanges() However, if I edit a value programatically on the DataGridView, the DataTable.GetChanges() returns a NullReferenceException as if no change took place. I know it saved to the DataTable, because I can look at it and see the updated value. Is there something else I need to call on the DataGridView after programatically updating it to make the changes noticable on the DataTable? Some type of commit method that is automatically called when a user edits? Right now I am bypassing the error by updating directly on the DataTable, but I know the DataGridView.Rows is a much smaller collection to loop for changing than the DataTable.Rows (due to filtering already in place). Should I worry about this efficiency issue at all? Thanks, Pualee

      P Offline
      P Offline
      Patrick Etc
      wrote on last edited by
      #2

      The datagridview exists solely for the user's benefit. If you want to programatically modify a data set, modify it in memory - your DataTable directly. That is the correct approach.

      P 1 Reply Last reply
      0
      • P Patrick Etc

        The datagridview exists solely for the user's benefit. If you want to programatically modify a data set, modify it in memory - your DataTable directly. That is the correct approach.

        P Offline
        P Offline
        Pualee
        wrote on last edited by
        #3

        Ok, thanks, I was worried I would never get answered :)

        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