Home Forums WPF controls Xceed DataGrid for WPF How to set the active row in code

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

    I am attempting to set the active row and cell in code and then put the grid into EditMode.

    However if I set the SelectedIndex on the grid, the CurrentItem is null, even although the SelectedItem returns the System.Data.DataRowView and the row on grid is visibly selected.

    If I cannot get the DataRow that is currently active, I cannot put it in edit mode.

    So the question is, how to I set the active row and cell and then cause the grid to go into edit mode from code?

    Imported from legacy forums. Posted by Kendrew (had 3036 views)

    Xceed Support
    Member
    Post count: 5658

    The SelectedItem/SelectedItems/SelectedIndex properties really represents the user selection…

    To determine/set what item is current “active”, you need to use the CurrentItem/CurrentColumn property.

    example:
    <hr>

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

    DataRow row = myGridControl.ItemContainerGenerator.ContainerFromItem(myGridControl.CurrentItem) as DataRow;

    row.BeginEdit();
    <hr>

    Note: Because of UI virtualization, it is possible that the container returned by the ContainerFromItem() function is null, you would need to exectute a BringIntoView() to compensate this situation.

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks Marc, this works.

    As an aside, why does

    DataGridCommands.BeginEdit.Execute(null, myGridControl);

    not work as opposed to row.BeginEdit()?

    and further to this, when would you expect us to use the commands versus explicit method calls?

    Imported from legacy forums. Posted by Kendrew (had 319 views)

    Xceed Support
    Member
    Post count: 5658

    When we created the BeginEdit, EndEdit and CancelEdit commands, we designed it in such a way that they could be raised on any element “inside” the scope of the DataRow (since edition is tightly linked with the concept of Rows)…

    Calling the BeginEdit command on that DataGridControl did not make sense at the time, since the DataGridControl itself was non-editable (i.e Its row were), but at the light of previous comments on the same matter, we are currently considering making it possible to call BeginEdit, EndEdit, CancelEdit directly on the DataGridControl (which would include support for the commands).

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

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