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 doesn't save the data

datagrid doesn't save the data

Scheduled Pinned Locked Moved C#
questiontutorialannouncement
6 Posts 3 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.
  • D Offline
    D Offline
    denizmercan
    wrote on last edited by
    #1

    I set up the datasource myDataGrid.DataSource= myDataSet.Tables[0].DefaultView; When I scroll the cursor to next row, datagrid updates the dataset. It's ok. But without doing it, datagrid doesn't update the dataset. myDataSet.Tables[0].Rows.Count is 0 and myDataSet.Tables[0].DefaultView.Count is 1. For example user can enter some data to datagrid then after closes the window. Datagrid doesn't affect the dataset row. I need to say "save data" to datagrid. How can I do this? Thanks

    A H 2 Replies Last reply
    0
    • D denizmercan

      I set up the datasource myDataGrid.DataSource= myDataSet.Tables[0].DefaultView; When I scroll the cursor to next row, datagrid updates the dataset. It's ok. But without doing it, datagrid doesn't update the dataset. myDataSet.Tables[0].Rows.Count is 0 and myDataSet.Tables[0].DefaultView.Count is 1. For example user can enter some data to datagrid then after closes the window. Datagrid doesn't affect the dataset row. I need to say "save data" to datagrid. How can I do this? Thanks

      A Offline
      A Offline
      Anfernius
      wrote on last edited by
      #2

      Try to accept the changes in your datasource. ((DataSet)(myDataGrid.DataSource)).AcceptChanges(); or simply DataSet1.AcceptChanges(); Anfernius

      D H 2 Replies Last reply
      0
      • A Anfernius

        Try to accept the changes in your datasource. ((DataSet)(myDataGrid.DataSource)).AcceptChanges(); or simply DataSet1.AcceptChanges(); Anfernius

        D Offline
        D Offline
        denizmercan
        wrote on last edited by
        #3

        It doesn't work. Because data is in the datagrid. Datagrid has to send the data to dataset Thanks for your interest.

        1 Reply Last reply
        0
        • A Anfernius

          Try to accept the changes in your datasource. ((DataSet)(myDataGrid.DataSource)).AcceptChanges(); or simply DataSet1.AcceptChanges(); Anfernius

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

          All that does is mark the rows as unchanged so that if you passed the DataSet to DataAdapter.Update, no rows would be updated in your database (or other data store).

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          • D denizmercan

            I set up the datasource myDataGrid.DataSource= myDataSet.Tables[0].DefaultView; When I scroll the cursor to next row, datagrid updates the dataset. It's ok. But without doing it, datagrid doesn't update the dataset. myDataSet.Tables[0].Rows.Count is 0 and myDataSet.Tables[0].DefaultView.Count is 1. For example user can enter some data to datagrid then after closes the window. Datagrid doesn't affect the dataset row. I need to say "save data" to datagrid. How can I do this? Thanks

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

            This is just the way the DataGrid works (as well as other controls). The changes aren't commited until the control looses focus. For a little bit more understanding, see the DataGridColumnStyle.Commit method documentation in the .NET Framework SDK. If you want to force the text (or whatever) to be commited, then you could, for example, call DataGrid.EndEdit before your Form closing (like overriding the OnClosing method or handling the Closing event). See that method documentation in the .NET Framework SDK for more information.

            Microsoft MVP, Visual C# My Articles

            D 1 Reply Last reply
            0
            • H Heath Stewart

              This is just the way the DataGrid works (as well as other controls). The changes aren't commited until the control looses focus. For a little bit more understanding, see the DataGridColumnStyle.Commit method documentation in the .NET Framework SDK. If you want to force the text (or whatever) to be commited, then you could, for example, call DataGrid.EndEdit before your Form closing (like overriding the OnClosing method or handling the Closing event). See that method documentation in the .NET Framework SDK for more information.

              Microsoft MVP, Visual C# My Articles

              D Offline
              D Offline
              denizmercan
              wrote on last edited by
              #6

              thanks. EndEdit works fine.

              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