XML文件显示、修改、查找
2004-09-01 10:03
399 查看
public class Form1 : System.Windows.Forms.Form
?{
??private System.Windows.Forms.DataGrid dataGrid1;
??private System.Windows.Forms.OpenFileDialog openFileDialog1;
??private System.Windows.Forms.TabControl tabControl1;
??private System.Windows.Forms.TabPage tabPageNormal;
??private System.Windows.Forms.TabPage tabPageSearch;
??private System.Windows.Forms.Panel panel1;
??private System.Windows.Forms.Button btnSearch;
??private System.Windows.Forms.TextBox tbValue;
??private System.Windows.Forms.ComboBox cmbField;
??private System.Windows.Forms.DataGrid dataGrid2;
??private System.Windows.Forms.Button btnClose;
??private System.Windows.Forms.Button btnReadXml;
??private System.Windows.Forms.Button btnUpdate;
??///
??/// 必需的设计器变量。
??///
??private System.ComponentModel.Container components = null;
??public Form1()
??{
???//
???// Windows 窗体设计器支持所必需的
???//
???InitializeComponent();
???//
???// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
???//
??}
??///
??/// 清理所有正在使用的资源。
??///
??protected override void Dispose( bool disposing )
??{
???if( disposing )
???{
????if (components != null)
????{
?????components.Dispose();
????}
???}
???base.Dispose( disposing );
??}
???DataSet
???ds = new DataSet();
??///
??/// 应用程序的主入口点。
??///
??[STAThread]
??static void Main()
??{
???Application.Run(new Form1());
??}
??///
??/// 更新XML文件
??///
??///
??///
??private void btnUpdate_Click(object sender, System.EventArgs e)
??{
???ds.WriteXml(this.openFileDialog1.FileName);
???MessageBox.Show("更新完成!");
???this.dataGrid1.Focus();
??}
??///
??/// 读取XML文件
??///
??///
??///
??private void btnReadXml_Click(object sender, System.EventArgs e)
??{
???this.openFileDialog1.Filter = "数据文件|*.xml";
???if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
???{
????// 将读入的XML文件作为数据源绑定到DataGrid上
????ds.Reset();
????ds.ReadXml(this.openFileDialog1.FileName);
????this.dataGrid1.DataSource = ds;
????this.dataGrid1.Focus();
???}
??}
??///
??/// 选择某个子表时修改‘列表’
??///
??///
??///
??private void dataGrid1_DataSourceChanged(object sender, System.EventArgs e)
??{???
???// 如果子表名不存在
???if (this.dataGrid1.DataMember == "")
???{
????this.btnSearch.Enabled = false;
????this.tbValue.Clear();
????this.tbValue.Enabled = false;
????this.cmbField.Items.Clear();
???}?// 子表存在,将所有字段名赋值给ComboBox
???else
???{
????this.cmbField.Items.Clear();
????this.cmbField.Items.Add("请选择字段");
????foreach (DataColumn dc in ds.Tables[this.dataGrid1.DataMember].Columns)
????{
?????this.cmbField.Items.Add(dc.ColumnName);
????}
????this.cmbField.SelectedIndex = 0;
???}
??}
??///
??/// 用户选择了一个列名
??///
??///
??///
??private void cmbField_SelectedIndexChanged(object sender, System.EventArgs e)
??{
???if (this.cmbField.SelectedIndex != 0)
????this.tbValue.Enabled = true;
???else
????this.tbValue.Enabled = false;
??}
??///
??/// 用户输入了要搜索的内容
??///
??///
??///
??private void tbValue_TextChanged(object sender, System.EventArgs e)
??{
???if (this.tbValue.Text.Trim().Length > 0)
????this.btnSearch.Enabled = true;
???else
????this.btnSearch.Enabled = false;
??}
??///
??/// 用户点击了“搜索”按钮
??///
??///
??///
??private void btnSearch_Click(object sender, System.EventArgs e)
??{
???// 将搜索结果存入一个DataView
???DataView
????dvSearch = new DataView();
???dvSearch.Table = ds.Tables[this.dataGrid1.DataMember];
???dvSearch.RowFilter = this.cmbField.Text + "='" + this.tbValue.Text.Trim() + "'";
???// 显示 DataView 的内容
???this.dataGrid2.DataSource = dvSearch;
???this.tabControl1.SelectedTab = this.tabPageSearch;
???this.tbValue.Clear();
??}
??///
??/// 关闭--查询结果页
??///
??///
??///
??private void btnClose_Click(object sender, System.EventArgs e)
??{
???this.tabControl1.SelectedTab = this.tabPageNormal;
??}
?}
?{
??private System.Windows.Forms.DataGrid dataGrid1;
??private System.Windows.Forms.OpenFileDialog openFileDialog1;
??private System.Windows.Forms.TabControl tabControl1;
??private System.Windows.Forms.TabPage tabPageNormal;
??private System.Windows.Forms.TabPage tabPageSearch;
??private System.Windows.Forms.Panel panel1;
??private System.Windows.Forms.Button btnSearch;
??private System.Windows.Forms.TextBox tbValue;
??private System.Windows.Forms.ComboBox cmbField;
??private System.Windows.Forms.DataGrid dataGrid2;
??private System.Windows.Forms.Button btnClose;
??private System.Windows.Forms.Button btnReadXml;
??private System.Windows.Forms.Button btnUpdate;
??///
??/// 必需的设计器变量。
??///
??private System.ComponentModel.Container components = null;
??public Form1()
??{
???//
???// Windows 窗体设计器支持所必需的
???//
???InitializeComponent();
???//
???// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
???//
??}
??///
??/// 清理所有正在使用的资源。
??///
??protected override void Dispose( bool disposing )
??{
???if( disposing )
???{
????if (components != null)
????{
?????components.Dispose();
????}
???}
???base.Dispose( disposing );
??}
???DataSet
???ds = new DataSet();
??///
??/// 应用程序的主入口点。
??///
??[STAThread]
??static void Main()
??{
???Application.Run(new Form1());
??}
??///
??/// 更新XML文件
??///
??///
??///
??private void btnUpdate_Click(object sender, System.EventArgs e)
??{
???ds.WriteXml(this.openFileDialog1.FileName);
???MessageBox.Show("更新完成!");
???this.dataGrid1.Focus();
??}
??///
??/// 读取XML文件
??///
??///
??///
??private void btnReadXml_Click(object sender, System.EventArgs e)
??{
???this.openFileDialog1.Filter = "数据文件|*.xml";
???if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
???{
????// 将读入的XML文件作为数据源绑定到DataGrid上
????ds.Reset();
????ds.ReadXml(this.openFileDialog1.FileName);
????this.dataGrid1.DataSource = ds;
????this.dataGrid1.Focus();
???}
??}
??///
??/// 选择某个子表时修改‘列表’
??///
??///
??///
??private void dataGrid1_DataSourceChanged(object sender, System.EventArgs e)
??{???
???// 如果子表名不存在
???if (this.dataGrid1.DataMember == "")
???{
????this.btnSearch.Enabled = false;
????this.tbValue.Clear();
????this.tbValue.Enabled = false;
????this.cmbField.Items.Clear();
???}?// 子表存在,将所有字段名赋值给ComboBox
???else
???{
????this.cmbField.Items.Clear();
????this.cmbField.Items.Add("请选择字段");
????foreach (DataColumn dc in ds.Tables[this.dataGrid1.DataMember].Columns)
????{
?????this.cmbField.Items.Add(dc.ColumnName);
????}
????this.cmbField.SelectedIndex = 0;
???}
??}
??///
??/// 用户选择了一个列名
??///
??///
??///
??private void cmbField_SelectedIndexChanged(object sender, System.EventArgs e)
??{
???if (this.cmbField.SelectedIndex != 0)
????this.tbValue.Enabled = true;
???else
????this.tbValue.Enabled = false;
??}
??///
??/// 用户输入了要搜索的内容
??///
??///
??///
??private void tbValue_TextChanged(object sender, System.EventArgs e)
??{
???if (this.tbValue.Text.Trim().Length > 0)
????this.btnSearch.Enabled = true;
???else
????this.btnSearch.Enabled = false;
??}
??///
??/// 用户点击了“搜索”按钮
??///
??///
??///
??private void btnSearch_Click(object sender, System.EventArgs e)
??{
???// 将搜索结果存入一个DataView
???DataView
????dvSearch = new DataView();
???dvSearch.Table = ds.Tables[this.dataGrid1.DataMember];
???dvSearch.RowFilter = this.cmbField.Text + "='" + this.tbValue.Text.Trim() + "'";
???// 显示 DataView 的内容
???this.dataGrid2.DataSource = dvSearch;
???this.tabControl1.SelectedTab = this.tabPageSearch;
???this.tbValue.Clear();
??}
??///
??/// 关闭--查询结果页
??///
??///
??///
??private void btnClose_Click(object sender, System.EventArgs e)
??{
???this.tabControl1.SelectedTab = this.tabPageNormal;
??}
?}
相关文章推荐
- XML文件显示、修改、查找
- c#环境XML文件创建、修改、删除、查找相关操作
- Asp.net中C#增加删除查找与修改xml文件元素节点
- 使用xom实现xml文件数据的查找,删除,修改(完整beta版,daya原创)
- C#中使用XmlDocument类来创建和修改XML格式的数据文件
- Android button, xml文件定义形状,代码中修改背景颜色
- AS3 操作XML,增加、删除、修改、查找
- Linux查找最近修改的文件
- Unity中的XML文件创建,读取,修改,添加
- 修改文件显示路径
- webStorm支持.wxml文件高亮显示
- 奇怪的问题:在IE6中显示FTP中的文件修改时间少一年
- 解决修改CSS文件后网页显示不生效问题
- 【java开发系列】— JDOM创建、修改、删除、读取XML文件
- [Shell]使用find命令查找最近修改过的文件
- tomcat图片上传指定位置并显示(修改配置文件)
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)
- Mac下显示隐藏文件 以及修改 hosts文件内容
- asp.net C#对xml文档创建 修改 删除 查找
- 图像保存到XML文件和从XML中取出图像显示