1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinSuppressLine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.DataSource = GetTable();
DataGridViewImageColumn imgColumn = new DataGridViewImageColumn();
imgColumn.Name = "Image";
imgColumn.HeaderText = "Suppression";
imgColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
imgColumn.Image=WinSuppressLine.Properties.Resources.BitmapCroix;
this.dataGridView1.Columns.Add (imgColumn);
}
private DataTable GetTable()
{
DataTable table = new DataTable("Person");
table.Columns.Add(new DataColumn("Nom",typeof(string)));
table.Columns.Add(new DataColumn("Salaire",typeof(decimal )));
AddRowToTable(table, "Harry", 2500.0);
AddRowToTable(table, "Sally", 4200.0);
AddRowToTable(table, "Roy", 3255.4);
AddRowToTable(table, "Pris", 1254.3);
return table;
}
private void AddRowToTable(DataTable dt, string itemNom,double itemSalaire)
{
DataRow dr=dt.NewRow();
dr[0]=itemNom;
dr[1]=itemSalaire;
dt.Rows.Add(dr);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = this.dataGridView1.CurrentRow;
if (row == null ) return;
if (e.RowIndex == this.dataGridView1.NewRowIndex) return; // nouvelle ligne ne peut etre supprimée
if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Image")
{
this.dataGridView1.Rows.Remove(row);
}
}
}
} |
Partager