Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

TQ – DataGridView

Thèmes des Questions – C# (C Sharp)



L’objectif est d’utiliser le composant visuel DataGridView pour afficher des tables.

1°) Compléter l’IHM de gauche afin qu’au lancement le composant visuel DataGridView affiche directement la table suivante :

2°) Le bouton charger XML permet de charger une autre table stockée dans un fichier XML “NotesEtudiant.xml”, comme ci-dessous :

3°) Le bouton Sauver XML envoie un fenêtre de dialogue avant de sauvegarder au format XML le contenu de la table actuellement présente dans le DataGridView :

4°) Le bouton Effacer supprime les données présntes dans le DataGridView.

using System;
 using System.Drawing;
 using System.Collections;
 using System.ComponentModel;
 using System.Windows.Forms;
 using System.Data;
 using System.IO;
 using System.Xml;
 namespace cci
 {
 public class FormDataGridView : System.Windows.Forms.Form
 {
 private DataSet unDataset = new DataSet();
 private DataGridView dataGridView1;
 private Button buttonLoad;
 private Button buttonClear;
 private Button buttonSave;
 private System.ComponentModel.Container components = null;
 public FormDataGridView()
 {
 InitializeComponent();
 }
 protected override void Dispose(bool disposing)
 {
 if (disposing)
 {
 if (components != null)
 {
 components.Dispose();
 }
 }
 base.Dispose(disposing);
 }
 region Windows Form Designer generated code
 private void InitializeComponent()
 {
 this.buttonLoad = new System.Windows.Forms.Button();
 this.dataGridView1 = new System.Windows.Forms.DataGridView();
 this.buttonClear = new System.Windows.Forms.Button();
 this.buttonSave = new System.Windows.Forms.Button();
 ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
 this.SuspendLayout();
 // 
 // buttonLoad
 // 
 this.buttonLoad.Location = new System.Drawing.Point(12, 178);
 this.buttonLoad.Name = "buttonLoad";
 this.buttonLoad.Size = new System.Drawing.Size(111, 23);
 this.buttonLoad.TabIndex = 3;
 this.buttonLoad.Text = "Charger XML";
 this.buttonLoad.Click += new System.EventHandler(this.buttonLoad_Click);
 // 
 // dataGridView1
 // 
 this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells;
 this.dataGridView1.Location = new System.Drawing.Point(1, 1);
 this.dataGridView1.Name = "dataGridView1";
 this.dataGridView1.Size = new System.Drawing.Size(397, 153);
 this.dataGridView1.TabIndex = 4;
 this.dataGridView1.Text = "dataGridView1";
 // 
 // buttonClear
 // 
 this.buttonClear.Location = new System.Drawing.Point(149, 178);
 this.buttonClear.Name = "buttonClear";
 this.buttonClear.Size = new System.Drawing.Size(75, 23);
 this.buttonClear.TabIndex = 5;
 this.buttonClear.Text = "Effacer";
 this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
 // 
 // buttonSave
 // 
 this.buttonSave.Location = new System.Drawing.Point(241, 178);
 this.buttonSave.Name = "buttonSave";
 this.buttonSave.Size = new System.Drawing.Size(118, 23);
 this.buttonSave.TabIndex = 6;
 this.buttonSave.Text = "Sauver XML";
 this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
 // 
 // FormDataGridView
 // 
 this.AutoScaleDimensions = new System.Drawing.Size(5, 13);
 this.ClientSize = new System.Drawing.Size(401, 213);
 this.Controls.Add(this.buttonSave);
 this.Controls.Add(this.buttonClear);
 this.Controls.Add(this.dataGridView1);
 this.Controls.Add(this.buttonLoad);
 this.Name = "FormDataGridView";
 this.Text = "DataGridView";
 this.Load += new System.EventHandler(this.FormDataGridView_Load);
 ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
 this.ResumeLayout(false);
 }
 endregion
 static void Main()
 {
 Application.Run(new FormDataGridView());
 }
 private void buttonLoad_Click(object sender, EventArgs e)
 {
 // …………………..
 }
 private void buttonClear_Click(object sender, EventArgs e)
 {
 // …………………..
 }
 private void buttonSave_Click(object sender, EventArgs e)
 {
 // …………………..
 }
 private void initRows()
 {
 // …………………..
 }
 private void initColumns()
 {
 // …………………..
 }
 private void FormDataGridView_Load(object sender, EventArgs e)
 {
 initColumns();
 initRows();
 }
 }
 }

Comments are closed, but trackbacks and pingbacks are open.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More