Home Forums WPF controls Xceed DataGrid for WPF Force Update of Row

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

    Hi,

    How do you suggest forcing the update of a row when the grid loses focus?

    Thanks,
    Darrel

    Imported from legacy forums. Posted by Darrel (had 7309 views)

    Xceed Support
    Member
    Post count: 5658

    Can you provide more context on what you are trying to achieve?

    Are you refering to a DataRow, a custom made row? a Header?

    What are you trying to refresh? Content of cells?

    I ask all these questions because depending on the answers, my own answer can be very different.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 459 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    I have many Controls on the Window and one of these is a DataGridControl. When the user is updating the control, he is able to update one or more cells in a row and that marks the row as being edited (as expected). If the user presses the Enter key, the row is commited (as expected).

    However, if the user does not press enter and instead selects a different control on the Window, the grid row remains in edit. I would like the grid row to be commited (in the same way as for the Enter key), when the user selects another control on the Window.

    I’m not sure how to answer your first question. My grid data is based off an ItemCollection (i.e. ItemsSource is null but Items is not null). My end goal to to ensure that when I read Items, the contents reflects what is displayed on screen (and, if the grid row is not commited, it does not).

    Does this help?

    Thanks,
    Darrel

    Imported from legacy forums. Posted by Darrel (had 935 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Darrel, your description effectively helps determining the situation.

    This problem is currently under investigation, in the mean time, there is effectively a workaround you can use to prevent this situation:

    – Handle the PreviewMouseDown event on the top level element (Page/Window).
    – Handle the PreviewGotKeyboardFocus().

    – In the handlers, ensure that the original source is not coming from the DataGridControl (see Visual.IsDescendantOf() ). If the original source is not a descendent of the DataGridControl, then you can do the following to update the Row:

    <code>
    DataRow myRow = myGrid.ItemContainerGenerator.GetContainerForItem( myGrid.CurrentItem ) as DataRow;

    if(myRow != null)
    {
    myRow.EndEdit();
    }
    </code>

    Note: Visual.IsDescendant() does not work well when used in conjunction with Popup elements… So if you are using a DatePicker or a ComboBox, you might run into some problems. (workaround would be to determine by yourself by walking up the visual/logical tree if the original source is a descendant)

    Imported from legacy forums. Posted by Marcus [Xceed] (had 475 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    The last part of your comment got cut off…is there something here I should watch out for?

    Thanks,
    Darrel

    Imported from legacy forums. Posted by Darrel (had 399 views)

    Xceed Support
    Member
    Post count: 5658

    reposting without the code:

    Hi Darrel, your description effectively helps determining the situation.

    This problem is currently under investigation, in the mean time, there is effectively a workaround you can use to prevent this situation:

    – Handle the PreviewMouseDown event on the top level element (Page/Window).
    – Handle the PreviewGotKeyboardFocus().

    – In the handlers, ensure that the original source is not coming from the DataGridControl (see Visual.IsDescendantOf() ). If the original source is not a descendent of the DataGridControl, then you can do the following to update the Row:

    (code)

    Note: Visual.IsDescendant() does not work well when used in conjunction with Popup elements… So if you are using a DatePicker or a ComboBox, you might run into some problems. (workaround would be to determine by yourself by walking up the visual/logical tree if the original source is a descendant)

    Imported from legacy forums. Posted by Marcus [Xceed] (had 472 views)

    Xceed Support
    Member
    Post count: 5658

    Hi,

    Just wanted to drop-in on you concerning the issue where the row currently in edition does not leave edition mode when focus is moved elsewhere in the window/page.

    After analyzing this thoroughly, we arrived at the conclusion that it would be best fitted NOT to automatically “end” edition on the currently edited row when the DataGridControl loses focus.

    The 2 primary reasons behind this are:

    – We cannot assert what are the needs of each and every user. It might be possible that some people would like to perform actions in another control based on the row currently in edition ( I have no specific examples yet ).

    – Since we have a validation scheme on the DataGridControl, automatically ending an edition could result in a validation error (DataGridValidationException). Under such circumstances, the row in edition would remain in edition (and any actions performed on the data would be done on the “non-edited”, without any particular indications of the problem).

    However, we acknowledge that we need a solution that allows users that encountered the same problem as you have to overcome it easily.

    The fix we are proposing is to add functions on the DataGridControl class to allow easily ending edition ( or cancelling it), without the need to fetch the DataRow for the CurrentItem.

    This would allow ensuring that if you need “up-to-date” data, you’d have it easily. You’d also be able to easily detect that edition cannot be “ended” (DataGridValidationException) and decide whether or not you want to proceed with your action.

    If this solution is problematic for your needs, we’d like to hear from you. This is to make sure that we are not leaving specific needs “un-addressed”.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 5205 views)

    User (Old forums)
    Member
    Post count: 23064

    Hes there been any updates in the DataGrid that address this issue?

    Imported from legacy forums. Posted by Chris (had 3317 views)

    Xceed Support
    Member
    Post count: 5658

    Yes, as stated in previous post, methods have been added to the DataGridControl class to allow quickly committing/cancelling edits made without having to fetch the DataRow for the CurrentItem.

    These methods are called “EndEdit()” and “CancelEdit()”.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 4518 views)

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