Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exporter DataGrid vers un Document XML

Utilisation,de,la,classe,'XmlTextReader',pour,lire,un,document,XML
{filelink=16389}

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml;
 
public class DataGridVersXML : System.Windows.Forms.Form
{
    private System.Windows.Forms.Button btnEngDtGrid;
   private System.Windows.Forms.DataGrid MonDataGrid;
   private System.ComponentModel.Container components = null;
 
   public DataGridVersXML() {
      InitializeComponent();
      charger();
   }
    void charger()
    {
        DataSet ds = new DataSet();
        ds.ReadXml("Operations.xml", XmlReadMode.InferSchema);
        MonDataGrid.SetDataBinding(ds, "Clients");
    }
   private void InitializeComponent() {
       this.btnEngDtGrid = new System.Windows.Forms.Button();
       this.MonDataGrid = new System.Windows.Forms.DataGrid();
       ((System.ComponentModel.ISupportInitialize)(this.MonDataGrid)).BeginInit();
       this.SuspendLayout();
       //
       // btnEngDtGrid
       //
       this.btnEngDtGrid.Location = new System.Drawing.Point(111, 206);
       this.btnEngDtGrid.Name = "btnEngDtGrid";
       this.btnEngDtGrid.Size = new System.Drawing.Size(307, 23);
       this.btnEngDtGrid.TabIndex = 1;
       this.btnEngDtGrid.Text = "Enregistrer le DataGrid dans un document XML";
       this.btnEngDtGrid.Click += new System.EventHandler(this.btnEngDtGrid_Click_1);
       //
       // MonDataGrid
       //
       this.MonDataGrid.DataMember = "";
       this.MonDataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
       this.MonDataGrid.Location = new System.Drawing.Point(1, 0);
       this.MonDataGrid.Name = "MonDataGrid";
       this.MonDataGrid.Size = new System.Drawing.Size(581, 200);
       this.MonDataGrid.TabIndex = 3;
       //
       // DataGridVersXML
       //
       this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
       this.ClientSize = new System.Drawing.Size(579, 272);
       this.Controls.Add(this.MonDataGrid);
       this.Controls.Add(this.btnEngDtGrid);
       this.Name = "DataGridVersXML";
       this.Text = "Exporter DataGrid Vers  Document XML";
       ((System.ComponentModel.ISupportInitialize)(this.MonDataGrid)).EndInit();
       this.ResumeLayout(false);
 
   }
 
   static void Main()
   {
      Application.Run(new DataGridVersXML());
   }
 
    private void btnEngDtGrid_Click_1(object sender, EventArgs e)
    {
      DataSet ds = (DataSet) MonDataGrid.DataSource;
      ds.WriteXml("DataGrid.xml",XmlWriteMode.IgnoreSchema);
    }
 
}
 
/*
 
//Fichier XML: Operation.xml
 
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="MesExemples.xsl"?>
<MesOperations>
    <Clients>
        <IDClient>CCLiege</IDClient>
        <Entreprise>Genital</Entreprise>
        <Nom-Contact>Frederic Moulard</Nom-Contact>
        <Fonction-Contact>D.G Commercial</Fonction-Contact>
        <Adresse>15 Rue X</Adresse>
        <Ville>Paris</Ville>
        <CodePostal>2025</CodePostal>
        <Pays>France</Pays>
        <Tel>20-30-14-30-65</Tel>
        <Fax>20-30-14-30-66</Fax>
    </Clients>
    <Clients>
        <IDClient>CCVerge</IDClient>
        <Entreprise>XMey</Entreprise>
        <Nom-Contact>Herve Banste</Nom-Contact>
        <Fonction-Contact>PDG</Fonction-Contact>
        <Adresse>30, rue des Galliers</Adresse>
        <Ville>Marseille</Ville>
        <CodePostal>13008</CodePostal>
        <Pays>France</Pays>
        <Tel>32-15-22-16-63</Tel>
        <Fax>32-15-22-16-64</Fax>
    </Clients>
    <Clients>
        <IDClient>CCDerge</IDClient>
        <Entreprise>Fourgon</Entreprise>
        <Nom-Contact>Samuel Etienne</Nom-Contact>
        <Fonction-Contact>D.G Commercial</Fonction-Contact>
        <Adresse>Cener Str. 213</Adresse>
        <Ville>Berlin</Ville>
        <CodePostal>12209</CodePostal>
        <Pays>Allemagne</Pays>
        <Tel>044-2014587</Tel>
        <Fax>044-2014588</Fax>
    </Clients>
</MesOperations>
 
*/

No comments yet.

Leave a Comment