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. DataBinding between a DataTable and a TextBox

DataBinding between a DataTable and a TextBox

Scheduled Pinned Locked Moved C#
questionhelpannouncement
4 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.
  • K Offline
    K Offline
    Kit Fisto
    wrote on last edited by
    #1

    Hello. I have a question that i would like to ask all the codeproject members. I have this cenario: TextBox.DataBindings.Add("Text", DataTable, "Field", false, DataSourceUpdateMode.OnPropertyChanged) A textbox is binded to a DataTable field. When i change the text on the textbox the cell from the datatable receives the new value, but the RowState of the current row doesn't changes to Modified, it keeps the Unchanged state. Only when i change to another row in the DataTable (the DataTable is binded to a DataGrdiView) that the RowState of that row is changed to Modified. The problem is that when i have only one row and the user saves the information, i use a batch update to save the changes in the DataTable, but as the row keeps the Unchanged State is doesn't gets to the update. Is there any way to solve this? Thanks in advance.

    H K 2 Replies Last reply
    0
    • K Kit Fisto

      Hello. I have a question that i would like to ask all the codeproject members. I have this cenario: TextBox.DataBindings.Add("Text", DataTable, "Field", false, DataSourceUpdateMode.OnPropertyChanged) A textbox is binded to a DataTable field. When i change the text on the textbox the cell from the datatable receives the new value, but the RowState of the current row doesn't changes to Modified, it keeps the Unchanged state. Only when i change to another row in the DataTable (the DataTable is binded to a DataGrdiView) that the RowState of that row is changed to Modified. The problem is that when i have only one row and the user saves the information, i use a batch update to save the changes in the DataTable, but as the row keeps the Unchanged State is doesn't gets to the update. Is there any way to solve this? Thanks in advance.

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      It is possible that the Row is still in Edit Mode. When the user saves, does your code call EndEdit? If this is a possibility, see How to: Commit In-Process Edits on Data-Bound Controls Before Saving Data[^] on MSDN.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      1 Reply Last reply
      0
      • K Kit Fisto

        Hello. I have a question that i would like to ask all the codeproject members. I have this cenario: TextBox.DataBindings.Add("Text", DataTable, "Field", false, DataSourceUpdateMode.OnPropertyChanged) A textbox is binded to a DataTable field. When i change the text on the textbox the cell from the datatable receives the new value, but the RowState of the current row doesn't changes to Modified, it keeps the Unchanged state. Only when i change to another row in the DataTable (the DataTable is binded to a DataGrdiView) that the RowState of that row is changed to Modified. The problem is that when i have only one row and the user saves the information, i use a batch update to save the changes in the DataTable, but as the row keeps the Unchanged State is doesn't gets to the update. Is there any way to solve this? Thanks in advance.

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        Right before you call update on the data set, call this:

        private void CommitChanges(DataSet ds)
        {
        foreach (DataTable dt in ds.Tables)
        {
        foreach (DataRow dr in ds.Tables)
        {
        dr.EndEdit();
        }
        }
        }

        Or, you could first subscribe to the ColumnChanged event on the table

        dt.ColumnChanged += new DataColumnChangeEventHandler(dt_ColumnChanged);

        then in the event do this:

        static void dt_ColumnChanged(object sender, DataColumnChangeEventArgs e)
        {
        e.Row.EndEdit();
        }

        Everything makes sense in someone's mind

        modified on Wednesday, October 7, 2009 11:28 AM

        K 1 Reply Last reply
        0
        • K Kevin Marois

          Right before you call update on the data set, call this:

          private void CommitChanges(DataSet ds)
          {
          foreach (DataTable dt in ds.Tables)
          {
          foreach (DataRow dr in ds.Tables)
          {
          dr.EndEdit();
          }
          }
          }

          Or, you could first subscribe to the ColumnChanged event on the table

          dt.ColumnChanged += new DataColumnChangeEventHandler(dt_ColumnChanged);

          then in the event do this:

          static void dt_ColumnChanged(object sender, DataColumnChangeEventArgs e)
          {
          e.Row.EndEdit();
          }

          Everything makes sense in someone's mind

          modified on Wednesday, October 7, 2009 11:28 AM

          K Offline
          K Offline
          Kit Fisto
          wrote on last edited by
          #4

          Thanks to the both of you. Although i'm using .net 2.0 the answer from Henry Minute was correct for that i thank you. The asnwer from KMAROIS was exactly what i was looking for. Thanks :thumbsup:

          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