Results 1 to 2 of 2

Thread: DataGridView and changes not made to a cell

  1. #1

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007

    DataGridView and changes not made to a cell

    I have a DGV bound to a data adapter. I have a button that loads a form with a reference to the DGV row. When the form is loaded, it has a TextBox to type a value, that modifies one of the cells of the row. When the form closes, the cell.value is properly modified, but saving the DGV doesn't save the new value of the cell to the DB table. I'm assuming this happens because the DGV hasn't had physical interaction. Also, this particular field is a password field, so the whole column is being hidden from the view.

    It seems that a DGV change is noted by physically clicking in a cell and it stores some data telling the adapter there have been changes. The thing is, this is done on a per cell basis, and only if the cell has been clicked. Well, this cell is hidden, so even though the value will be changed, you could never click or select that cell.

    Is there any other way to force the DGV to accept changes made to it from outside actions of just assigning the cell.value from a button click and not phsyically changing it in the DGV?

    Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7

    SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
    [Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]

    [.NET and MySQL Quick Guide]

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: DataGridView and changes not made to a cell

    First up, you don't have a grid bound to a data adapter. The adapter moves data between the database and a DataTable. It's the DataTable that contains the data and it's the DataTable that contains the data. As such, you don't save the grid. You use the adapter to save the changes from the DataTable back to the database. What's in the grid is irrelevant. It's just their for user interaction.

    If you want to make changes via a TextBox then you should be binding that TextBox to the DataTable too. The user edits the data in the TextBox, that gets propagated to the DataTable and that gets saved. The grid is irrelevant.

    You should be binding your DataTable to a BindingSource and binding that to your controls also. You can then call EndEdit on that before saving to ensure that all changes are committed first.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width