I have DataGrid in my wpf application. It is having a few events. I need to edit the datagrid cell in single click. Presently it is altering when I double click the cell. I have taken a stab at something. However, it is not working for me. The rows and columns are not consistent. Dynamically I will create column for Datagrid.
this is my code..
Xaml:
<DataGrid Name="dgTest" AutoGenerateColumns="True" CanUserResizeColumns="False" CanUserAddRows="False"
ItemsSource="{Binding NotifyOnSourceUpdated=True}"
HorizontalAlignment="Left"
SelectionMode="Single"
SelectionUnit="Cell"
IsSynchronizedWithCurrentItem="True"
CellStyle="{StaticResource DataGridBorder}"
CurrentCellChanged="dgTest_CurrentCellChanged"
CellEditEnding="dgTest_CellEditEnding"
GotFocus="dgTest_GotFocus" LostFocus="dgTest_LostFocus"
GotKeyboardFocus="TextBoxGotKeyboardFocus" LostKeyboardFocus="TextBoxLostKeyboardFocus"
AutoGeneratingColumn="dgTest_AutoGeneratingColumn"/>
I had a go at adding some code to the "GotFocus" event. yet its not working for me. Any help would be truly valued.
CS:
private void dgTest_GotFocus(object sender, RoutedEventArgs e)
{
// Lookup for the source to be DataGridCell
if (e.OriginalSource.GetType() == typeof(DataGridCell))
{
// Starts the Edit on the row;
DataGrid grd = (DataGrid)sender;
grd.BeginEdit(e);
}
}