title: DataGrid cell single click edit mode in wpf c#?
body: <p>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. </p>
  
  <p>this is my code..</p>
  
  <p>Xaml:</p>
  
  <pre><code> &lt;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"/&gt;
  </code></pre>
  
  <p>I had a go at adding some code to the "GotFocus" event. yet its not working for me. Any help would be truly valued.</p>
  
  <p>CS:</p>
  
  <pre><code> 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);
          }
  
      }     
  </code></pre>