Click here to Skip to main content
15,896,154 members
Articles / Programming Languages / C#

Bind XML TreeView with GridView/DataGrid

Rate me:
Please Sign up or sign in to vote.
1.00/5 (11 votes)
22 Nov 2006CPOL 70.6K   1.2K   19  
This sample code is used to populate XML data into a GridView with a TreeView format.
namespace XMLTreeview
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.XMLGridView = new System.Windows.Forms.DataGridView();
            this.Column1 = new System.Windows.Forms.DataGridViewImageColumn();
            this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.LoadXMLButton = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.XMLGridView)).BeginInit();
            this.SuspendLayout();
            // 
            // XMLGridView
            // 
            this.XMLGridView.AllowUserToAddRows = false;
            this.XMLGridView.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.Raised;
            this.XMLGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.XMLGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Column1,
            this.Column2,
            this.Column3});
            this.XMLGridView.Location = new System.Drawing.Point(0, 0);
            this.XMLGridView.Name = "XMLGridView";
            this.XMLGridView.RowHeadersVisible = false;
            this.XMLGridView.Size = new System.Drawing.Size(623, 478);
            this.XMLGridView.TabIndex = 3;
            this.XMLGridView.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.CityGridView_RowsAdded);
            this.XMLGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.CityGridView_CellContentClick);
            // 
            // Column1
            // 
            this.Column1.HeaderText = "";
            this.Column1.Name = "Column1";
            this.Column1.Width = 20;
            // 
            // Column2
            // 
            this.Column2.HeaderText = "";
            this.Column2.Name = "Column2";
            // 
            // Column3
            // 
            this.Column3.HeaderText = "";
            this.Column3.Name = "Column3";
            this.Column3.Width = 500;
            // 
            // LoadXMLButton
            // 
            this.LoadXMLButton.Location = new System.Drawing.Point(629, 0);
            this.LoadXMLButton.Name = "LoadXMLButton";
            this.LoadXMLButton.Size = new System.Drawing.Size(75, 23);
            this.LoadXMLButton.TabIndex = 1;
            this.LoadXMLButton.Text = "Load XML";
            this.LoadXMLButton.UseVisualStyleBackColor = true;
            this.LoadXMLButton.Click += new System.EventHandler(this.LoadXMLButton_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(804, 478);
            this.Controls.Add(this.LoadXMLButton);
            this.Controls.Add(this.XMLGridView);
            this.Name = "Form1";
            this.Text = "XMLTreeView";
            ((System.ComponentModel.ISupportInitialize)(this.XMLGridView)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.DataGridView XMLGridView;
        private System.Windows.Forms.Button LoadXMLButton;
        private System.Windows.Forms.DataGridViewImageColumn Column1;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
        private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Hi,
I have 5+ years of experience in Microsoft Technologies and have 2+ years of experience in .NET Technologies. Currenty I am woring in Visualsoft Technologies, Hyderabad and involed in Motorola projects. I feel in my carrier it's good projects. Because in this projects we are implementing the VS2005 and .NET 3.0 with Sqlserver 2005, also winfx.
SQL Server is my favourate subject, I was worked one ERP project as DBA. So it's was nice experience for me in SQL Server and
got BrainBench Certificate for .NET,DataBase and C#.


Comments and Discussions