This is a migrated thread and some comments may be shown as answers.

How to edit GridViewCell from code?

0 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 2
Anton asked on 12 Jul 2012, 11:14 AM
I want to add "paste to selected cell" command to Row. I don't want to change SelectionMode="Extended".
I've added RoutedUICommand:

private void PasteToCell_Executed(object sender, ExecutedRoutedEventArgs e)
{
            GridViewCell cell = e.OriginalSource as GridViewCell;
            if (cell != null)
            {
                var value = Clipboard.GetText();
                cell.BeginEdit();
                TextBox tb = (TextBox)cell.GetEditingElement();
1 ->          tb.Text = value;
2 ->          if (ApplicationCommands.Paste.CanExecute(value, tb))
                    ApplicationCommands.Paste.Execute(value, tb);
3 ->          cell.Value = value;
4 ->          cell.SetCurrentValue(GridViewCell.ValueProperty, value);
5 ->          cell.SetValue(GridViewCell.ValueProperty, value);
                cell.CommitEdit();
            }
}
No one work. I don't know how to realize this feature.

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Anton
Top achievements
Rank 2
Share this question
or