private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { using (var dbcontext = new Model.Context()) { int iSelectedGridIndex = dataGridView1.CurrentCell.ColumnIndex; if (iSelectedGridIndex != 0) { return; } int rowindex = dataGridView1.CurrentCell.RowIndex; int rowID = Int32.Parse(dataGridView1.Rows[rowindex].Cells[2].Value.ToString()); Model.archive model = dbcontext.Archives.SingleOrDefault(x => x.ID == rowID); dbcontext.Entry(model).State = EntityState.Deleted; dbcontext.SaveChanges(); List <Model.archive> lst = (from p in dbcontext.Archives where p.hesab == "1" select p).ToList(); dataGridView1.DataSource = lst; string imageName = model.imageName; var directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); System.IO.File.Delete(directory + imageName); } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { using (var dbcontext = new Model.Context()) { int iSelectedGridIndex = dataGridView1.CurrentCell.ColumnIndex; int rowindex = dataGridView1.CurrentCell.RowIndex; int rowID = Int32.Parse(dataGridView1.Rows[rowindex].Cells[2].Value.ToString()); Model.archive model = dbcontext.Archives.SingleOrDefault(x => x.ID == rowID); string imageName = ""; if (iSelectedGridIndex == 1) { imageName = model.imageName; } else if (iSelectedGridIndex == 0) { Model.tamin tmodel = dbcontext.tamins.SingleOrDefault(x => x.shomareSanad == model.shomareTamin); imageName = tmodel.imageName; } if (imageName != "") { try { var directory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); if (Path.GetExtension(imageName) == ".pdf") { try { factorPdf factore = new factorPdf(directory + imageName); factore.Show(); } catch (Exception error) { label1.Text = error.InnerException.Message; } } else { factorImage factor = new factorImage(directory + imageName); factor.Show(); } } catch (Exception error) { } } } }