Home Forums WPF controls Xceed DataGrid for WPF Question about saving data back to the database

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25945 |

    Hello,

    I have 2 questions….

    1) I have a project that is similar to the Databinding Sample (the datatable part). I would like to be able to save data back to the database when a user edits it. How would you go about doing this?

    2) Also how do you get some data from the currently selected row from 1 cell on that row?

    Thanks in advance!

    —Dave

    Imported from legacy forums. Posted by David (had 5543 views)

    Xceed Support
    Member
    Post count: 5658

    1- There are currently no built-in events that are raised when the edit process is finished; however, you could check a DataRow’s IsBeingEdited property in conjunction with its IsDirty property and save your changes when the value of the IsBeingEdited property returns to false(after being first set to true) and IsDirty is true.

    2- object data = ( ( System.Data.DataRow )this.gridControl.CurrentItem )[ 0 ];

    Imported from legacy forums. Posted by Jenny [Xceed] (had 385 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny. Thanks for your response.

    1) So it sounds like in a future version there might be a even that will be raised when a edit is successfully done (OnSuccessfulEdit)?
    Looking through the help files I am not seeing any events like OnCellChange or like a OnRowChange. Events that would be fired when you sucessfully move to another cell or row. I was figuring that I could use these events and save the data back to the database once these events are fired.

    Imported from legacy forums. Posted by David (had 422 views)

    Xceed Support
    Member
    Post count: 5658

    You could use the grid’s PropertyChanged event and check if CurrentItem changes.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 420 views)

    User (Old forums)
    Member
    Post count: 23064

    Is there a Event that is fired when you start to edit a cell?

    My thought is…

    When the above event is fired….I would then record the location of the cell….
    and as soon as the PropertyChanged event is fired I would then save the cell that was altered…and I would know the location of that changed cell because I recorded the location in the event that was fired when the cell was being edited.

    Imported from legacy forums. Posted by David (had 558 views)

    Xceed Support
    Member
    Post count: 5658

    Adding a PropertyChanged event for IsBeingEdited may do the trick although I have not tested this scenario.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 260 views)

    User (Old forums)
    Member
    Post count: 23064

    I almost got my program to work the way I would like it to.
    But I do have 1 last question.

    I initially thought the LostFocus event happened when you clicked on a control outside the grid…..but this is not the case…it is only fired when you click on another cell in the grid.
    Is there a event that fires when you leave the datagrid it loses focus?

    Imported from legacy forums. Posted by David (had 600 views)

    User (Old forums)
    Member
    Post count: 23064

    “There are currently no built-in events that are raised when the edit process is finished; however, you could check a DataRow’s IsBeingEdited property in conjunction with its IsDirty property and save your changes when the value of the IsBeingEdited property returns to false(after being first set to true) and IsDirty is true. “

    could someone provide some more detail on how this could be implemented? i’ve tried to do this but i don’t see the IsBeingEdited or IsDirty properties in the DataRow object.

    Imported from legacy forums. Posted by Jason (had 645 views)

    User (Old forums)
    Member
    Post count: 23064

    Well the IsBeingEdited property is in the datagrid itself and in the Cell object. The IsDirty property is in the Cell object. You can add a event (PropertyChanged event) that is fired when the IsBeingEdited property or the IsDirty property changes. You can use google and find some code examples of that.

    I decided not to do this….
    Instead when the PropertyChanged event is fired off by the datagrid I just save any changes that were made to the data. Its not the most elegant way to do things…
    It works….except when the datagrid loses focus.

    I am wondering if LostFocus is bugged. Because on other controls the LostFocus is called once you leave that control. But for the datagrid LostFocus seems to be called only when you move from cell to cell. And it isn’t called when you move to another control.

    Imported from legacy forums. Posted by David (had 6638 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.