BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
this.dataGrid.SelectionController = new GridSelectionControllerExt(this.dataGrid); public class GridSelectionControllerExt: GridCellSelectionController { public GridSelectionControllerExt(SfDataGrid grid) : base(grid) { } protected override void ProcessKeyDown(KeyEventArgs args) { base.ProcessKeyDown(args); if (args.Key == Key.Delete) { (this.DataGrid.DataContext as ViewModel).OrderInfoCollection.Remove(this.DataGrid.CurrentItem as Model); } } } |
Hi,
Since all your examples involve view model format. it is very hard for me to understand.
I am new to C# and wpf application. And I not using the view model in code. Can you please help me how to implement the same in the WPFSyncFusionPayPeriods.rar code?
protected override void ProcessKeyDown(KeyEventArgs args)
{
base.ProcessKeyDown(args);
if (args.Key == Key.Delete)
{
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Table1", connection);
try
{
cmd = new SqlCommand("DELETE FROM Table1 (ID,Name) WHERE (@ID)", connection);
cmd.Parameters.Add("@ID", SqlDbType.Int, 50, "ID");
SqlParameter parameter= cmd.Parameters.Add("@ID", SqlDbType.Int, 50, "ID");
da.DeleteCommand = cmd;
da.Fill(DS);
//To get the current position
int index = this.DataGrid.ResolveToRowIndex(this.DataGrid.CurrentItem);
int resolvedIndex = this.DataGrid.ResolveToRecordIndex(index);
System.Data.DataRow dr = DS.Tables[1].Rows[resolvedIndex];
//It gives the details about the current item and then remove the remove the record from
//the database based upon that record
dr["ID"] = ((System.Data.DataRowView)this.DataGrid.CurrentItem).Row.ItemArray[0];
DS.Tables[1].Rows.Remove(dr);
da.Update(DS);
}
catch
{
}
finally
{
//Here you can code your view updation process
}
}
} |