none
force update in datagridview RRS feed

  • Question

  • hi all.
    i have a problem with the standard datagridview control:
    on my form i have a datagridview control, bounded to a datatable.
    the datagridview is editable.
    after the user modified some data in a row, and clicks on "save" in my toolbar, i wrote:
    datatable dt=(DataTable)MyGrid.DataSource.GetChanges(DataRowState.MOdified);
    BUT - dt=null !!!!
    if and only if the user will click TAB or he will enter another row (force update on the grid) , dt will contain the changes !!!!
    is there a way to force the updates even if the user clicks on the toolbar , right after he updated the grids row?

     

    thank you.
    Sunday, October 21, 2007 2:18 PM

Answers

  •  

    Hi shachar8,

    Validation is a required part of validating and updating the data in a bound control. By default, toolbars and menus do not force validation for controls. Thus you need to force validation for the data bound control manually. Try the following code in ToolBarButton click event before you try to get the changes:

    Code Block

                this.Validate();

                MyGrid.EndEdit();

     

    Hope this helps.
    Best regards.
    Rong-Chun Zhang

    Tuesday, October 23, 2007 3:47 AM

All replies

  • Try MyGrid.EndEdit();  before you try and get the changes.

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.endedit.aspx

    Sunday, October 21, 2007 5:46 PM
  • no, it doesn't help.

     

    Monday, October 22, 2007 6:04 AM
  •  

    Hi shachar8,

    Validation is a required part of validating and updating the data in a bound control. By default, toolbars and menus do not force validation for controls. Thus you need to force validation for the data bound control manually. Try the following code in ToolBarButton click event before you try to get the changes:

    Code Block

                this.Validate();

                MyGrid.EndEdit();

     

    Hope this helps.
    Best regards.
    Rong-Chun Zhang

    Tuesday, October 23, 2007 3:47 AM
  • i have the same problem. validation is successful, the corresponding event is fired, but the changes of cell values are not stored in the datarow. i need to change the selected row, to have the new values in the datarow. this is not as i expect it.
    Tuesday, December 23, 2008 10:26 AM
  • Could you post the relevant code?
    ~~Bonnie Berent [C# MVP]
    Saturday, December 27, 2008 4:50 PM
  • I'm not good in English, but I had the same problem. This take me a mount of hours.

    The problem arrive when you have a record that is saved in the database, when is a data that is just in the DataSet but not saved in the DataBase, this problem do not appear.

    When a control Like a TextBox, ComboBox or a DataGridView is bounded to a DataSet and the current record is a record saved in the DataBase the changes in the DataSet is not reflected in the control.

    To solve the problem you can focus the control before change it, then change it and focus another control.

    Like this.

    textBox.Focus()

    data_set.tables(table_name).item("id") = 2

    textBox2.Focus()

    Friday, July 4, 2014 3:40 PM
  • It could also be simply that the changes to the DataTable are still in a Proposed state and some additional processing needs to be done before the Proposed changes get "commmitted" to the DataRow. I have two blog posts on this subject that I wrote a few years ago. They may shed some light on the issue:

    http://geek-goddess-bonnie.blogspot.com/2009/09/fun-with-datasets.html
    http://geek-goddess-bonnie.blogspot.com/2010/03/uncommitted-child-table-changes.html


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Proposed as answer by Yan Mbiya Wednesday, March 11, 2015 1:38 PM
    • Unproposed as answer by Yan Mbiya Wednesday, March 11, 2015 1:38 PM
    Saturday, July 5, 2014 4:33 PM
  • Hi, 

    to solve your problem tries this code:  facturesDataGridView.EndEdit()   ( on the leave event of the datagridview. )

    Wednesday, March 11, 2015 1:41 PM