Click here to Skip to main content
15,917,456 members
Home / Discussions / XML / XSL
   

XML / XSL

 
GeneralRe: How to send XMLdata to exe file Pin
yu-yu23-Oct-03 18:55
yu-yu23-Oct-03 18:55 
QuestionMSXML Parser??CreateNode???? Pin
xxhimanshu20-Oct-03 23:22
xxhimanshu20-Oct-03 23:22 
AnswerRe: MSXML Parser??CreateNode???? Pin
Philip Fitzsimons21-Oct-03 2:43
Philip Fitzsimons21-Oct-03 2:43 
GeneralXML round trip problems Pin
james-cxx20-Oct-03 14:01
james-cxx20-Oct-03 14:01 
GeneralRe: XML round trip problems Pin
Christian Graus20-Oct-03 15:17
protectorChristian Graus20-Oct-03 15:17 
GeneralRe: XML round trip problems Pin
james-cxx20-Oct-03 17:33
james-cxx20-Oct-03 17:33 
GeneralRe: XML round trip problems Pin
Christian Graus21-Oct-03 9:34
protectorChristian Graus21-Oct-03 9:34 
QuestionHow to save the content of Datagrid into XML file and retrieve the content into Datagrid? Pin
Cybermilky17-Oct-03 20:46
Cybermilky17-Oct-03 20:46 
I have a sample coding using C#.NET in Compact Framework. This code is about adding rows and columns in DataTable. Now, I want to save the content of the Datagrid into my XML file. How can I do this? Confused | :confused:

Then, I would like to retrive the content from the XML file into my Datagrid. How can I load it? Confused | :confused:

=====Code Start=====
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using System.XML;
using System.Windows.Forms.DataGrid;

class DataGridAdding : Form
{
private System.Data.DataTable dataTable;
private System.Windows.Forms.Button buttonAddColumn;
private System.Windows.Forms.Button buttonAddRow;
private System.Windows.Forms.Button buttonDeleteColumn;
private System.Windows.Forms.Button buttonDeleteRow;
private int maxColumnNumber;
private System.Windows.Forms.DataGrid dataGrid;
private int maxRowNumber;

public DataGridAdding()
{
maxColumnNumber = 0;
maxRowNumber = 0;

InitializeComponent();

// Create a DataTable of data to use.
InitializeTable();

// Bind the DataGrid to the DataTable.
dataGrid.DataSource = dataTable;
}

protected void InitializeComponent()
{
this.buttonAddColumn = new System.Windows.Forms.Button();
this.buttonAddRow = new System.Windows.Forms.Button();
this.buttonDeleteColumn = new System.Windows.Forms.Button();
this.buttonDeleteRow = new System.Windows.Forms.Button();
this.dataGrid = new System.Windows.Forms.DataGrid();
//
// buttonAddColumn
//
this.buttonAddColumn.Location = new System.Drawing.Point(5, 5);
this.buttonAddColumn.Size = new System.Drawing.Size(80, 20);
this.buttonAddColumn.Text = "Add Column";
this.buttonAddColumn.Click += new System.EventHandler(this.buttonAddColumn_Click);
//
// buttonAddRow
//
this.buttonAddRow.Location = new System.Drawing.Point(5, 30);
this.buttonAddRow.Size = new System.Drawing.Size(80, 20);
this.buttonAddRow.Text = "Add Row";
this.buttonAddRow.Click += new System.EventHandler(this.buttonAddRow_Click);
//
// buttonDeleteColumn
//
this.buttonDeleteColumn.Location = new System.Drawing.Point(90, 5);
this.buttonDeleteColumn.Size = new System.Drawing.Size(145, 20);
this.buttonDeleteColumn.Text = "Delete Current Column";
this.buttonDeleteColumn.Click += new System.EventHandler(this.buttonDeleteColumn_Click);
//
// buttonDeleteRow
//
this.buttonDeleteRow.Location = new System.Drawing.Point(90, 30);
this.buttonDeleteRow.Size = new System.Drawing.Size(145, 20);
this.buttonDeleteRow.Text = "Delete Current Row";
this.buttonDeleteRow.Click += new System.EventHandler(this.buttonDeleteRow_Click);
//
// dataGrid
//
this.dataGrid.Location = new System.Drawing.Point(0, 56);
this.dataGrid.Size = new System.Drawing.Size(240, 216);
this.dataGrid.Text = "dataGrid";
//
// DataGridAdding
//
this.Controls.Add(this.dataGrid);
this.Controls.Add(this.buttonAddColumn);
this.Controls.Add(this.buttonAddRow);
this.Controls.Add(this.buttonDeleteColumn);
this.Controls.Add(this.buttonDeleteRow);
this.Text = "DataGrid Sample";
}

private void InitializeTable()
{
int index;

// Create a DataTable named "Edit Table".
dataTable = new DataTable("Rows Cols Table");

// Create columns in the DataTable.
AddNewColumn();
AddNewColumn();
AddNewColumn();

// Add 20 rows of data to the DataTable.
for (index = 0; index < 20; index++)
{
AddNewRow();
}
}

private void AddNewColumn()
{
string newColumnName;
int index;

// Increment the max column number.
maxColumnNumber++;

// Construct name for new column.
newColumnName = "C " + maxColumnNumber.ToString();

// Create New Column.
dataTable.Columns.Add(newColumnName, Type.GetType("System.String"));

// Add data to each row in the table for the new column.
for (index = 0; index < dataTable.Rows.Count; index++)
{
dataTable.Rows[index][newColumnName] = "R " + index.ToString() + ", " + newColumnName;
}
}

private void AddNewRow()
{
DataRow dataRow;
int index;
string columnName;

// Increment the maximum row number.
maxRowNumber++;

// Create new row from DataTable.
dataRow = dataTable.NewRow();

// Add data to each column in the new row.
for (index = 0; index < dataTable.Columns.Count; index++)
{
columnName = dataTable.Columns[index].ColumnName;
dataRow[columnName] = "R " + maxRowNumber.ToString() + ", " + columnName;
}

dataTable.Rows.Add(dataRow);
}

private void buttonAddColumn_Click(object o, EventArgs e)
{
AddNewColumn();
}

private void buttonAddRow_Click(object o, EventArgs e)
{
AddNewRow();
}

private void buttonDeleteColumn_Click(object o, EventArgs e)
{
if (dataTable.Columns.Count > 0)
{
dataTable.Columns.RemoveAt(dataGrid.CurrentCell.ColumnNumber);
}
}

private void buttonDeleteRow_Click(object o, EventArgs e)
{
if (dataTable.Rows.Count > 0)
{
dataTable.Rows.RemoveAt(dataGrid.CurrentCell.RowNumber);
}
}

public static void Main(string [] args)
{
Application.Run(new DataGridAdding());
}
}
=====Code End=====

Please help~ Cry | :((
1. Save content of Datagrid into XML file.
2. Load content from XML file into Datagrid.
GeneralReally interesting problem ! Pin
pahluwalia17-Oct-03 11:52
pahluwalia17-Oct-03 11:52 
GeneralDataSet from XML Schema Pin
pahluwalia17-Oct-03 9:34
pahluwalia17-Oct-03 9:34 
GeneralXML Complex Type, DataSet Pin
pahluwalia17-Oct-03 6:36
pahluwalia17-Oct-03 6:36 
GeneralXML Transformation Trouble... Pin
CreProDes17-Oct-03 1:04
CreProDes17-Oct-03 1:04 
GeneralRe: XML Transformation Trouble... Pin
Philip Fitzsimons17-Oct-03 3:04
Philip Fitzsimons17-Oct-03 3:04 
GeneralRe: XML Transformation Trouble... Pin
CreProDes17-Oct-03 3:56
CreProDes17-Oct-03 3:56 
GeneralLookup Table (sort of) in XML Pin
Asad Hussain16-Oct-03 8:51
Asad Hussain16-Oct-03 8:51 
GeneralRe: Lookup Table (sort of) in XML Pin
Asad Hussain16-Oct-03 11:36
Asad Hussain16-Oct-03 11:36 
GeneralSystem.Xml Pin
Michael P Butler15-Oct-03 10:42
Michael P Butler15-Oct-03 10:42 
GeneralRe: System.Xml Pin
Nick Parker15-Oct-03 15:54
protectorNick Parker15-Oct-03 15:54 
QuestionWhat's the best XML format? Pin
Alvaro Mendez14-Oct-03 8:20
Alvaro Mendez14-Oct-03 8:20 
AnswerRe: What's the best XML format? Pin
Stuart Dootson14-Oct-03 9:22
professionalStuart Dootson14-Oct-03 9:22 
GeneralRe: What's the best XML format? Pin
Alvaro Mendez14-Oct-03 9:47
Alvaro Mendez14-Oct-03 9:47 
GeneralRe: What's the best XML format? Pin
Stuart Dootson14-Oct-03 11:34
professionalStuart Dootson14-Oct-03 11:34 
GeneralRe: What's the best XML format? Pin
CreProDes17-Oct-03 1:00
CreProDes17-Oct-03 1:00 
AnswerRe: What's the best XML format? Pin
Philip Fitzsimons17-Oct-03 3:09
Philip Fitzsimons17-Oct-03 3:09 
QuestionHow to Determine if element contains a given attribute Pin
MStanbrook13-Oct-03 9:31
MStanbrook13-Oct-03 9:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.