Home Forums WPF controls Xceed DataGrid for WPF CurrentItem = InsertionRow

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

    At Loaded time, you can do, in preparation for setting the keyboard focus to the data grid:

    CurrentColumn = Columns[0];
    CurrentItem = Items[0];

    But of course this only works when there are existing items. When there are not, the requirement is to set the current item to the insertion row so that the user can start typing the first new record:

    CurrentItem = InsertionRow; // InsertionRow reference has been retrieved as discussed in earlier posts.

    But this doesn’t work. Stepping through it with the debugger, after the CurrentItem = InsertionRow statement is executed, CurrentItem is still null (despite InsertionRow containing a valid reference); obviously it’s rejecting it for some reason, whereas it accepted the assignment to Items[0] (when there were existing items).

    Is this a bug, or am I doing something wrong?

    Imported from legacy forums. Posted by Russell (had 3020 views)

    Xceed Support
    Member
    Post count: 5658

    This is not a bug,

    dataGrid.CurrentItem = dataGrid.Items[0] statement refers to a data item and assigns it to the current item (which is good).

    dataGrid.CurrentItem = InsertionRowInstance statement refers to the container of a header item (which is not valid ).

    To set the InsertionRow as current, you have to refer to its data item:

    1)
    object insertionRowItem = dataGrid.GetItemFromContainer( InsertionRowInstance );
    dataGrid.CurrentItem = insertionRowItem;

    2)
    dataGird.CurrentItem = dataGrid.View.Headers[0]; // if you already know that first header is what you are looking for.

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

    User (Old forums)
    Member
    Post count: 23064

    Ah, that works, thanks!

    Curiously, dataGrid.CurrentItem = InsertionRowInstance does work when you do it in a PreviewKeyDown handler (which was the other context in which I used it). I guess, then, that’s a case of something happening to work that shouldn’t, and I should also use GetItemFromContainer there?

    Imported from legacy forums. Posted by Russell (had 346 views)

    User (Old forums)
    Member
    Post count: 23064

    Ah, it turns out that it also works if you just say CurrentItem = null, as long as you follow it with InsertionRowInstance.BeginEdit(). Which does actually make sense.

    Imported from legacy forums. Posted by Russell (had 4263 views)

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