User (Old forums)MemberMarch 27, 2008 at 7:44 amPost count: 23064
At Loaded time, you can do, in preparation for setting the keyboard focus to the data grid:
CurrentColumn = Columns;
CurrentItem = Items;
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 (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 SupportMemberMarch 27, 2008 at 8:06 amPost count: 5658
This is not a bug,
dataGrid.CurrentItem = dataGrid.Items 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:
object insertionRowItem = dataGrid.GetItemFromContainer( InsertionRowInstance );
dataGrid.CurrentItem = insertionRowItem;
dataGird.CurrentItem = dataGrid.View.Headers; // 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)MemberMarch 27, 2008 at 8:24 amPost 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)MemberMarch 27, 2008 at 9:06 amPost 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)
- You must be logged in to reply to this topic.