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. DataGrid row: RowState unchange problem

DataGrid row: RowState unchange problem

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

    Hi, I created a datagrid, bonding with a datatable, with some columns editable. If edit the fields in one row, and cursor stays in the same row,RowState is still "Unchanged", although the datatable has the new value now. RowState will be "Modified" only when I move the cursor to another row. But I want to save my changes to database without moving the cursors to other rows. How should I do it? BTW, I use : "if (r.RowState != DataRowState.Unchanged && r.RowState != DataRowState.Deleted)" to judge whether there are changes need to be saved. I don't want to remove this condition because it will cause a lot of unnecessary updates. Thanks.

    H 1 Reply Last reply
    0
    • C Chris 3

      Hi, I created a datagrid, bonding with a datatable, with some columns editable. If edit the fields in one row, and cursor stays in the same row,RowState is still "Unchanged", although the datatable has the new value now. RowState will be "Modified" only when I move the cursor to another row. But I want to save my changes to database without moving the cursors to other rows. How should I do it? BTW, I use : "if (r.RowState != DataRowState.Unchanged && r.RowState != DataRowState.Deleted)" to judge whether there are changes need to be saved. I don't want to remove this condition because it will cause a lot of unnecessary updates. Thanks.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Get the CurrencyManager for the DataGrid and call EndCurrentEdit like so:

      CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
      dataGrid1.DataSource, dataGrid1.DataMember];
      if (cm != null)
      cm.EndCurrentEdit();

      Also, use DataSet.GetChanges or DataTable.GetChanges and get the Count of rows for the tables. This is a better way of determining changes plus gives you a DataSet of just the changes so that you can pass that to your methods which update the data source (i.e., database). This will also be more efficient if you need to send this DataSet across application boundaries since it won't (potentially) require as much bandwidth since it would have fewer rows.

      Microsoft MVP, Visual C# My Articles

      C 1 Reply Last reply
      0
      • H Heath Stewart

        Get the CurrencyManager for the DataGrid and call EndCurrentEdit like so:

        CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
        dataGrid1.DataSource, dataGrid1.DataMember];
        if (cm != null)
        cm.EndCurrentEdit();

        Also, use DataSet.GetChanges or DataTable.GetChanges and get the Count of rows for the tables. This is a better way of determining changes plus gives you a DataSet of just the changes so that you can pass that to your methods which update the data source (i.e., database). This will also be more efficient if you need to send this DataSet across application boundaries since it won't (potentially) require as much bandwidth since it would have fewer rows.

        Microsoft MVP, Visual C# My Articles

        C Offline
        C Offline
        Chris 3
        wrote on last edited by
        #3

        Thanks a lot! CurrencyManager works fine for my case. Appreciate for your response!

        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