0
votes

I have a DataGrid and I want the user to be able to edit some of the columns, but only if they double click the cell first. At the minute if they single click the cell, then start typing it goes into edit mode instantly.

I have tried to use MouseDoubleClick event and disable readonly then but unable to set this property in code behind.

Any help/other suggestions? Thanks

1
Take a look at this and see if it helps you. social.msdn.microsoft.com/Forums/vstudio/en-US/… - Andrew Greatorex
Thats for not having to double click. But what I want is for the cell to be readonly unless i double click. Found a solution now anyway. but thanks - Danhol86

1 Answers

0
votes

I solved this by setting the column attribute IsReadOnly="True".

Then hooked into the event MouseDoubleClick for every cell.

<Style TargetType="{x:Type DataGridCell}">
    <EventSetter Event="MouseDoubleClick" Handler="DataGridCell_MouseDoubleClick" />
</Style>

and in the code behind:

private void DataGridCell_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    if (sender.GetType() == typeof(DataGridCell))
    {
         DataGridCell cell = sender as DataGridCell;
         cell.IsEditing = true;
    }
}

This seems to ignore the isreadonly property and I can successfully update the property after double clicking. You can also filter out certain columns at this point by name, but I don't require this.