Datagrid Xml : Xml DataGrid « XML « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » XML » Xml DataGrid 
30.27.2.Datagrid Xml
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Xml;

  public class XmlDataGridForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.DataGrid dgLateXmlBound;
    private System.Windows.Forms.Button cmdLoad;
    private System.Windows.Forms.Button cmdSave;
    private XmlDataDocument xdocSnowReports;
    private System.Windows.Forms.DataGridTableStyle dgsResorts;
    private System.Windows.Forms.DataGridTextBoxColumn tbcResort;
    private System.Windows.Forms.DataGridTextBoxColumn tbcSnowMin;
    private System.Windows.Forms.DataGridTextBoxColumn tbcSnowHigh;

    public XmlDataGridForm()
    {
      this.dgLateXmlBound = new System.Windows.Forms.DataGrid();
      this.cmdLoad = new System.Windows.Forms.Button();
      this.cmdSave = new System.Windows.Forms.Button();
      this.dgsResorts = new System.Windows.Forms.DataGridTableStyle();
      this.tbcResort = new System.Windows.Forms.DataGridTextBoxColumn();
      this.tbcSnowMin = new System.Windows.Forms.DataGridTextBoxColumn();
      this.tbcSnowHigh = new System.Windows.Forms.DataGridTextBoxColumn();
      ((System.ComponentModel.ISupportInitialize)(this.dgLateXmlBound)).BeginInit();
      this.SuspendLayout();
      // 
      // dgLateXmlBound
      // 
      this.dgLateXmlBound.DataMember = "";
      this.dgLateXmlBound.HeaderForeColor = System.Drawing.SystemColors.ControlText;
      this.dgLateXmlBound.Name = "dgLateXmlBound";
      this.dgLateXmlBound.Size = new System.Drawing.Size(432264);
      this.dgLateXmlBound.TabIndex = 0;
      this.dgLateXmlBound.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] {
                                                     this.dgsResorts});
      // 
      // cmdLoad
      // 
      this.cmdLoad.Location = new System.Drawing.Point(8280);
      this.cmdLoad.Name = "cmdLoad";
      this.cmdLoad.TabIndex = 1;
      this.cmdLoad.Text = "load";
      this.cmdLoad.Click += new System.EventHandler(this.cmdLoad_Click);
      // 
      // cmdSave
      // 
      this.cmdSave.Location = new System.Drawing.Point(96280);
      this.cmdSave.Name = "cmdSave";
      this.cmdSave.TabIndex = 2;
      this.cmdSave.Text = "save";
      this.cmdSave.Click += new System.EventHandler(this.cmdSave_Click);
      // 
      // dgsResorts
      // 
      this.dgsResorts.DataGrid = this.dgLateXmlBound;
      this.dgsResorts.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
                                                     this.tbcResort,
                                                     this.tbcSnowMin,
                                                     this.tbcSnowHigh});
      this.dgsResorts.HeaderForeColor = System.Drawing.SystemColors.ControlText;
      this.dgsResorts.MappingName = "Resort";
      // 
      // tbcResort
      // 
      this.tbcResort.Format = "";
      this.tbcResort.FormatInfo = null;
      this.tbcResort.HeaderText = "Resort name";
      this.tbcResort.MappingName = "Name";
      this.tbcResort.Width = 75;
      // 
      // tbcSnowMin
      // 
      this.tbcSnowMin.Format = "";
      this.tbcSnowMin.FormatInfo = null;
      this.tbcSnowMin.HeaderText = "Min snow";
      this.tbcSnowMin.MappingName = "SnowLow";
      this.tbcSnowMin.Width = 75;
      // 
      // tbcSnowHigh
      // 
      this.tbcSnowHigh.Format = "";
      this.tbcSnowHigh.FormatInfo = null;
      this.tbcSnowHigh.HeaderText = "Max snow";
      this.tbcSnowHigh.MappingName = "SnowHigh";
      this.tbcSnowHigh.Width = 75;
      // 
      // XmlDataGridForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(432309);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.cmdSave,
                                      this.cmdLoad,
                                      this.dgLateXmlBound});
      this.Name = "XmlDataGridForm";
      this.Text = "XML in DataGrid";
      ((System.ComponentModel.ISupportInitialize)(this.dgLateXmlBound)).EndInit();
      this.ResumeLayout(false);

      xdocSnowReports = new XmlDataDocument();
    }
    static void Main() 
    {
      Application.Run(new XmlDataGridForm());
    }

    private void cmdLoad_Click(object sender, System.EventArgs e)
    {
      xdocSnowReports.DataSet.ReadXml(new StreamReader("SampleData.xml"), XmlReadMode.InferSchema);
      dgLateXmlBound.SetDataBinding(xdocSnowReports.DataSet, "Resort");

      DataRow dr = xdocSnowReports.DataSet.Tables["SnowReports"].Rows[0];
      string strCaption = dr["Date"].ToString();
      this.dgLateXmlBound.CaptionText = "Snow report on " + strCaption;
    }

    private void cmdSave_Click(object sender, System.EventArgs e)
    {
      xdocSnowReports.DataSet.WriteXml("hardcodedfilename.xml");
    }
  }
30.27.Xml DataGrid
30.27.1.Load Xml document to DataGrid
30.27.2.Datagrid Xml
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.