Search code examples
c#wpfdatagriddevexpressdevexpress-wpf

WPF Datagrid copy last row of grid to new row in grid (Devexpress)


there is thing that I want to do but I stack as a dummy. Here is the steps;

  1. When user hit the ctrl + D button on Datagrid
  2. The Last row of datagrid values will copied to clippopard or somewhere (eg.CopyToClipboard func.)
  3. From clipboard or something else to again it could be a function e.g. pastToclipboard or we can use InitNewRowEventArgs which it gave us access the RowHandle funciton

Here is code I done so far.

private void dtg_tabletrial_KeyDown(object sender, KeyEventArgs e)
 {
  if (e.Key == Key.D && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
        {  
          MessageBox.Show("You hit ctrl + D");
        }
 }

 private void dtg_view_InitNewRow(object sender, DevExpress.Xpf.Grid.InitNewRowEventArgs e)
    {
        dtg_tabletrial.SetCellValue(e.RowHandle, "UserName", "emre");
        dtg_tabletrial.SetCellValue(e.RowHandle, "Surname", "newcompany");
        dtg_tabletrial.SetCellValue(e.RowHandle, "Address", "new addres");
        dtg_tabletrial.SetCellValue(e.RowHandle, "Phone", "new phone");   
    }

Solution

  • Thanks again to Mike Strobel , but I also included another solution for that. I'm writing down here to someone who will need it.

    Peace

     private void dtg_tabletrial_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.D && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
    
                DataGridTrialTable ff = new DataGridTrialTable();
                ff.Address = dtgtrialTable.LastOrDefault().Address;
                ff.UserName = dtgtrialTable.LastOrDefault().UserName;
                ff.Phone = dtgtrialTable.LastOrDefault().Phone;
                ff.Surname = dtgtrialTable.LastOrDefault().Surname;
    
                dtgtrialTable.Add(ff);
            }
        }