IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

Colonne de Supression DataGridView C#|WindowsForm


Sujet :

Windows Forms

  1. #1
    Membre régulier
    Homme Profil pro
    BAC +3
    Inscrit en
    Octobre 2018
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : BAC +3

    Informations forums :
    Inscription : Octobre 2018
    Messages : 164
    Points : 92
    Points
    92
    Par défaut Colonne de Supression DataGridView C#|WindowsForm
    Hello tout le monde , j'ai un dataGridView qui alimenter par un retour de requête SQL et j'aimerai qu'en plus des données envoyé par la base, ajouter une colonne supplémentaire ou je joins un image de croix rouge pour supprimer la ligne entière.

    Comme ça :

    Nom : Capt.png
Affichages : 110
Taille : 2,2 Ko

    Une idée ?

    Merci

  2. #2
    Membre habitué
    Homme Profil pro
    Passioné ...
    Inscrit en
    Juillet 2020
    Messages
    145
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Passioné ...
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2020
    Messages : 145
    Points : 158
    Points
    158
    Par défaut
    Bonjour,

    La question c'est : ajouter la croix rouge ? supprimer la ligne ? Navré mais pour aider il faut comprendre la question ....

  3. #3
    Membre régulier
    Homme Profil pro
    BAC +3
    Inscrit en
    Octobre 2018
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : BAC +3

    Informations forums :
    Inscription : Octobre 2018
    Messages : 164
    Points : 92
    Points
    92
    Par défaut
    Pardon alors oui c'est ajouter la colonne qui contient la croix rouge

  4. #4
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Tu peux faire ceci:
    code behind.cs exemple( l'image est en resources du projet) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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); 
                    }
     
             }
        }
    }
    bon code...

  5. #5
    Membre régulier
    Homme Profil pro
    BAC +3
    Inscrit en
    Octobre 2018
    Messages
    164
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : BAC +3

    Informations forums :
    Inscription : Octobre 2018
    Messages : 164
    Points : 92
    Points
    92
    Par défaut
    Super merci pour le coup de pouce !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 02/10/2006, 19h33
  2. [VB.Net 05] Addition dans une colonne d'un DataGridView
    Par collaud_vb dans le forum Windows Forms
    Réponses: 13
    Dernier message: 26/09/2006, 16h53
  3. [C#]Customiser les colonnes d'un datagridview
    Par cmoiscrat dans le forum Windows Forms
    Réponses: 2
    Dernier message: 10/09/2006, 10h47
  4. [C#][VS 2005]Supprimer la première colonne dans un DatagridView
    Par cmoiscrat dans le forum Windows Forms
    Réponses: 2
    Dernier message: 29/06/2006, 15h20
  5. [VB.NET] Calculs dans une colonne d'un datagridview
    Par boulete dans le forum Windows Forms
    Réponses: 3
    Dernier message: 31/03/2006, 15h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo