Saturday 7 March 2009

Single Click edit in WPF DataGridView

If you have a datagrid view with a check box the fefault behaviour is that you need to click 2 times to check a check box. 1 click it to select the cell and the second to check the box. To get arround this:

In the XAML File:
UserControl.Resources
. Style TargetType="{x:Type my:DataGridCell}"
EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown" /EventSetter
/Style
...
/UserControl.Resources


In the CS-File:
using Microsoft.Windows.Controls;...
private void DataGridCell_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
PartnerRe.WPF.Utilities.Tools.SingleClickEditing(sender as DataGridCell);
}