//加载描述的XML
private bool loadXML()
{ //创建DataTable对象dt
DataTable dt = new DataTable("clientXML");
//创建列
dt.Columns.Add(new DataColumn("IP", typeof(string)));
dt.Columns.Add(new DataColumn("端口", typeof(string)));
dt.Columns.Add(new DataColumn("事件", typeof(string)));
dt.Columns.Add(new DataColumn("时间", typeof(string)));
dt.Columns.Add(new DataColumn("备注1", typeof(string)));
dt.Columns.Add(new DataColumn("备注2", typeof(string))); //装载文档
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load("..\\..\\ClientStatus.xml");
//获取跟节点
XmlNode xn = XmlDoc.SelectSingleNode("client");
//获取子节点集合
XmlNodeList xnl = xn.ChildNodes;
foreach (XmlNode xn_temp in xnl)
{
//将节点转为元素,以便得到节点的属性
XmlElement xe = (XmlElement)xn_temp;
DataRow row = dt.NewRow();
row["IP"] = xe.GetAttribute("ip").ToString();
row["端口"] = xe.GetAttribute("port").ToString();
row["事件"] = xe.GetAttribute("event").ToString();
row["时间"] = xe.GetAttribute("datetime").ToString();
row["备注1"] = xe.GetAttribute("memo1").ToString();
row["备注2"] = xe.GetAttribute("memo2").ToString();
dt.Rows.Add(row);
}
DataSet ds = new DataSet("client");
ds.Tables.Add(dt); this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = ds.Tables[].TableName; return true; }
<?xml version="1.0" encoding="utf-8" ?>
<client>
<point ip="127.0.0.1" port="40940">
<event>发送链路请求帧 </event>
<datetime> 207.9.13 19:14</datetime>
<memo1>尚未回复 </memo1>
<memo2> 无</memo2>
</point> <point ip="197.0.0.1" port="940">
<event>回复链路请求帧 </event>
<datetime> 2017.9.13 19:14</datetime>
<memo1>尚未回复2 </memo1>
<memo2>无2</memo2>
</point>
</client>

datagridview绑定xml的更多相关文章

  1. [WinForm] DataGridView 绑定 DT && ComboBox 列绑定 Dict

    一  需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面 ...

  2. C# Winform中DataGridView绑定后DataGridViewCheckBoxColumn无法显示的问题

    在控件DataGridView绑定数据源后,发现DataGridViewCheckBoxColumn不能显示当前的check值.经过一番努力,现将完整代码奉献出来,仅供参考. 错误代码: /*禁止自动 ...

  3. C# DataGridView绑定数据源的几种常见方式

    开始以前,先认识一下WinForm控件数据绑定的两种形式,简单数据绑定和复杂数据绑定. 1. 简单的数据绑定 例1 using (SqlConnection conn = new SqlConnect ...

  4. DataGridView 绑定 List

    DataGridView 绑定 List<T> 不会自动更新 正确方式是将  List<T> 设置为 BindingList<T> 即可 (双向绑定)

  5. DataGridView绑定BindingList<T>带数据排序的类

    本文章转载:http://yuyingying1986.blog.hexun.com/30905610_d.html DataGridView绑定List<T>类时候,不会自动的进行排序. ...

  6. DataGridView绑定数据源

    给DataGridView绑定数据源比較简单,方法主要有两种: 1.直接在控件属性中绑定数据源,这样的方法最简单,但它是直接连接数据库的,这样就和传DataTable的后果差点儿相同了,所以还是尽量避 ...

  7. WinForm DataGridView 绑定泛型List(List<T>)/ArrayList不显示的原因和解决

    背景:无意间遇到了一个不大不小的问题,希望对一些遇到的人有所帮助! 一.问题 WinForm DataGridView 绑定泛型List (List<T>)/ArrayList不显示,UI ...

  8. c# winform 中DataGridView绑定List<T> 不能显示数据

    遇到问题 DataGridView绑定List后,List更新后再次绑定不显示数据 datagridview 绑定数据源的时候 用List是不能显示修改内容的..要用binginglist<T& ...

  9. DataGridView绑定泛型List时,利用BindingList来实现增删查改

    DataGridView绑定泛型List时,利用BindingList来实现增删查改  一.   DataGridView绑定泛型List的种种 1.DataGridView数据绑定对比(DataTa ...

随机推荐

  1. librec库

    固定初始化矩阵值 net.librec.math.structure -> class DenseMatrix -> void init()

  2. SQL Server Profiler 跟踪远程服务器的语句

    同事测试软件报错,想连Ta的数据库跟踪下语句,结果提示:      对比了下自己的探查器设置,勾选几个事件就可以了:

  3. erl_0016 《硝烟中的erlang》 读书笔记003 “error_logger 爆炸”

    error_logger 爆炸 具有讽刺意味的是,负责错误日志的进程竟然是最为脆弱的之一.在Erlang的缺省安装中,error_logger39负责记录日志(写入磁盘或者发送到网络上),它的速度要比 ...

  4. HDU - 1142:A Walk Through the Forest (拓扑排序)

    Jimmy experiences a lot of stress at work these days, especially since his accident made working dif ...

  5. 微信小程序异常解析

    文件解析错误 SyntaxError: Unexpected end of JSON input: 在子目录下添加空白的json配置文件是会出现报错,其原因是因为文件内容空白 pages/index/ ...

  6. 每天一个linux命令:【转载】ls命令

    ls命令是linux下最常用的命令.ls命令就是list的缩写,缺省下ls用来打印出当前目录的清单,如果ls指定其他目录,那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...

  7. appium python实例脚本1

    #coding=utf-8import os, time, unittestfrom appium import webdriver PATH = lambda p:os.path.abspath(o ...

  8. 《DSP using MATLAB》示例Example7.5

    代码: h = [-4, 1, -1, -2, 5, 6, 6, 5, -2, -1, 1, -4]; M = length(h); n = 0:M-1; [Hr, w, b, L] = Hr_Typ ...

  9. ZBar的简单使用

    NSRunLoop类声明的编程接口用于管理输入源对象.一个NSRunLoop对象处理像来自窗体系统中的鼠标和键盘事件,NSPORT对象和NSConnection连接对象这类的输入源.一个NSRunLo ...

  10. Android中执行的错误:java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: findLibrary returned null.

    今天在使用百度地图的时候执行发现报错: 明明已经增加了liblocSDK3.so.但总是无法定位.提示错误java.lang.UnsatisfiedLinkError: Couldn't load l ...