C#读取xml文件数据。显示在datagridview控件问题

图片说明

如上图所示框起来的是xml文件的一个子节点内容,这个子节点中包括了不同结构的子节点数据。可以仔细看下这个xml结构,现在我想把这个节点的数据按照下面的格式显示在文本框以及datagridview中。其他同等节点类似,具体代码该怎么写呢?

图片说明

xml文件下载地址

9个回答

图片说明

ccc9149
未知昵称 问题点已经提在下面的回答里面了
大约一年之前 回复
ccc9149
未知昵称 https://pan.baidu.com/s/16NtlWAcWncW-Sl3MfzeOLQ 有问题的代码
大约一年之前 回复
caozhy
贵阳老马马善福专门编写代码的老马就是我! 回复ccc9149: 代码传网盘或者贴在下面回答的区域里面
大约一年之前 回复
ccc9149
未知昵称 怎么获取到Serviceinterfaces下 METHODS节点的内容。。改了你的程序, public NodeCollections Children02 { get { var sub = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "ARGUMENTS"); if (sub == null) sub = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "METHODS"); return new NodeCollections(sub); } } public bool MoveNext()这个在报错??
大约一年之前 回复
ccc9149
未知昵称 自己改好了
大约一年之前 回复
ccc9149
未知昵称 var root1 = new Node(doc.ChildNodes[1].ChildNodes[1].ChildNodes[1].ChildNodes[1].ChildNodes[0]);能找到xml文件中的Tuner,但是怎么把Tuner下的节点添加到treeview中呢?试了好几个。没写对
大约一年之前 回复
caozhy
贵阳老马马善福专门编写代码的老马就是我! 回复ccc9149: private void LoadTV(TreeNode tn) 这个方法是加载treeview的,你根据tn判断下,如果到了某一层,你就return而不继续加载就可以了。
大约一年之前 回复
ccc9149
未知昵称 在左侧的treeview中不显示图片中框出来的子节点,例如不显示SRdsSettingInit下面的子节点sw_rds_ta 、sw_rds_pty等,怎么改一下你的代码?右边的datagridview中还是按照现在正常显示内容
大约一年之前 回复

图片说明

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Q694896
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public Form1(XmlNode pnode) : this()
        {
            parentNode = pnode;
            if (this.Height > 160)
            {
                this.Height -= 40;
                this.Width -= 60;
            }
        }

        string clickme = "click me";

        XmlNode parentNode;

        class DataItem
        {
            public string ShortName { get; set; }
            public string Category { get; set; }
            public string BaseTypeRef { get; set; }
            public object Node { get; set; }
            public DataItem(string a, string b, string c)
            {
                ShortName = a;
                Category = b;
                BaseTypeRef = c;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<DataItem> data = new List<DataItem>();
            IEnumerable<XmlNode> nodes;
            if (parentNode == null)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(@"TunerServiceInterface.arxml");
                nodes = doc.GetElementsByTagName("IMPLEMENTATION-DATA-TYPE").Cast<XmlNode>();
            }
            else
            {
                nodes = parentNode.ChildNodes.Cast<XmlNode>().Where(x => x.Name == "IMPLEMENTATION-DATA-TYPE-ELEMENT");
                try
                {
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox1.Text = parentNode.ParentNode.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SHORT-NAME").InnerText;
                    textBox2.Text = parentNode.ParentNode.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "CATEGORY").InnerText;
                }
                catch { }
            }
            foreach (XmlNode node in nodes)
            {
                string sn = "";
                try
                {
                    sn = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SHORT-NAME").InnerText;
                    var c = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "CATEGORY").InnerText;
                    var btf = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SW-DATA-DEF-PROPS").InnerText;
                    data.Add(new DataItem(sn, c, btf) { Node = node });
                }
                catch
                {
                    if (node.ChildNodes.Cast<XmlNode>().Any(x => x.Name == "SUB-ELEMENTS"))
                    {
                        data.Add(new DataItem(sn, clickme, "") { Node = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SUB-ELEMENTS") });
                    }
                }
            }
            dataGridView1.DataSource = data;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex <= 0) return;
            string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            if (s == clickme)
            {
                //var f = new Form1((XmlNode)dataGridView1.Rows[e.RowIndex].Cells[dataGridView1.Rows[e.RowIndex].Cells.Count - 1].Value);
                //f.StartPosition = FormStartPosition.CenterParent;
                //f.ShowDialog();
                this.parentNode = (XmlNode)dataGridView1.Rows[e.RowIndex].Cells[dataGridView1.Rows[e.RowIndex].Cells.Count - 1].Value;
                Form1_Load(this, null);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s = null;
            try
            {
                this.parentNode = this.parentNode.ParentNode.ParentNode;
                s = parentNode.ParentNode.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "CATEGORY").InnerText;
            }
            catch
            {
                this.parentNode = null;
            }
            Form1_Load(this, null);
        }
    }
}

caozhy
贵阳老马马善福专门编写代码的老马就是我! 稍等,知道你的意思了
大约一年之前 回复

图片说明

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Q694896
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public Form1(XmlNode pnode) : this()
        {
            parentNode = pnode;
            if (this.Height > 160)
            {
                this.Height -= 40;
                this.Width -= 60;
            }
        }

        string clickme = "click me";

        XmlNode parentNode;

        class DataItem
        {
            public string ShortName { get; set; }
            public string Category { get; set; }
            public string BaseTypeRef { get; set; }
            public object Node { get; set; }
            public DataItem(string a, string b, string c)
            {
                ShortName = a;
                Category = b;
                BaseTypeRef = c;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<DataItem> data = new List<DataItem>();
            IEnumerable<XmlNode> nodes;
            if (parentNode == null)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(@"TunerServiceInterface.arxml");
                nodes = doc.GetElementsByTagName("IMPLEMENTATION-DATA-TYPE").Cast<XmlNode>();
            }
            else
            {
                nodes = parentNode.ChildNodes.Cast<XmlNode>().Where(x => x.Name == "IMPLEMENTATION-DATA-TYPE-ELEMENT");
                textBox1.Text = parentNode.ParentNode.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SHORT-NAME").InnerText;
                textBox2.Text = parentNode.ParentNode.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "CATEGORY").InnerText;
            }
            foreach (XmlNode node in nodes)
            {
                string sn = "";
                try
                {
                    sn = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SHORT-NAME").InnerText;
                    var c = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "CATEGORY").InnerText;
                    var btf = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SW-DATA-DEF-PROPS").InnerText;
                    data.Add(new DataItem(sn, c, btf) { Node = node });
                }
                catch
                {
                    if (node.ChildNodes.Cast<XmlNode>().Any(x => x.Name == "SUB-ELEMENTS"))
                    {
                        data.Add(new DataItem(sn, clickme, "") { Node = node.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SUB-ELEMENTS") });
                    }
                }
            }
            dataGridView1.DataSource = data;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            if (s == clickme)
            {
                var f = new Form1((XmlNode)dataGridView1.Rows[e.RowIndex].Cells[dataGridView1.Rows[e.RowIndex].Cells.Count - 1].Value);
                f.StartPosition = FormStartPosition.CenterParent;
                f.ShowDialog();
            }
        }
    }
}
ccc9149
未知昵称 你仔细看下我提的需求,我不需要弹出新的窗口,显示数据,你看下我在datagridview里面数据是怎么把xml的内容填进去的
大约一年之前 回复
caozhy
贵阳老马马善福专门编写代码的老马就是我! 另外几列你按照shortname和category的类似的做,就可以了。
大约一年之前 回复
 namespace Q694896
{
    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.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 18);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "shortname";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(74, 15);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(133, 20);
            this.textBox1.TabIndex = 1;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(230, 18);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(51, 13);
            this.label2.TabIndex = 2;
            this.label2.Text = "catregory";
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(287, 15);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(133, 20);
            this.textBox2.TabIndex = 3;
            // 
            // dataGridView1
            // 
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Location = new System.Drawing.Point(14, 50);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(733, 390);
            this.dataGridView1.TabIndex = 4;
            this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(759, 452);
            this.Controls.Add(this.dataGridView1);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.DataGridView dataGridView1;

    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Collections;

namespace Q695201
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"TunerServiceInterface.arxml");
            var root = new Node(doc.ChildNodes[1].ChildNodes[1].ChildNodes[0].ChildNodes[1].ChildNodes[1]);
            TreeNode tn = new TreeNode() { Text = root.ShortName, Tag = root };
            treeView1.Nodes.Add(tn);
            LoadTV(tn);
            treeView1.ExpandAll();
            treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
            treeView1.SelectedNode = tn;
        }

        void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            Node node = e.Node.Tag as Node;

            textBox1.Text = node.ShortName;
            textBox2.Text = node.Category;
            List<DGVItem> list = new List<DGVItem>();
            foreach (Node n in node.Children)
            {
                DGVItem item = new DGVItem();
                item.shortname = n.ShortName;
                item.category = n.Category;
                Node n1 = n.Children.Cast<Node>().FirstOrDefault();
                if (n1 != null)
                {
                    item.shortname1 = n1.ShortName;
                    item.category1 = n1.Category;
                    item.arraysize = n1.ArraySuze;
                    item.arraysizesemantic = n1.ArraySizeSemantic;
                    item.basetyperef = n1.BaseTypeRef;
                }
                list.Add(item);
            }
            DataGridView dgv = new DataGridView();
            dgv.Dock = DockStyle.Fill;
            panel1.Controls.Clear();
            panel1.Controls.Add(dgv);
            dgv.DataSource = list;
        }

        private void LoadTV(TreeNode tn)
        {
            Node n = tn.Tag as Node;
            if (n != null)
            {
                foreach (Node item in n.Children)
                {
                    TreeNode tn1 = new TreeNode() { Text = item.ShortName, Tag = item };
                    tn.Nodes.Add(tn1);
                    LoadTV(tn1);
                }
            }
        }
    }

    class Node
    {
        private XmlNode _base;

        public Node(XmlNode baseNode)
        {
            _base = baseNode;
        }

        public NodeCollections Children
        {
            get
            {
                var sub = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SUB-ELEMENTS");
                if (sub == null)
                    sub = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "ELEMENTS");
                return new NodeCollections(sub);
            }
        }

        public string ShortName
        {
            get
            {
                var node = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SHORT-NAME");
                if (node != null) return node.InnerText; else return "";
            }
        }

        public string Category
        {
            get
            {
                var node = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "CATEGORY");
                if (node != null) return node.InnerText; else return "";
            }
        }

        public string BaseTypeRef
        {
            get
            {
                var node = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "SW-DATA-DEF-PROPS");
                if (node != null) return node.InnerText; else return "";
            }
        }

        public string ArraySuze
        {
            get
            {
                var node = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "ARRAY-SIZE");
                if (node != null) return node.InnerText; else return "";
            }
        }
        public string ArraySizeSemantic
        {
            get
            {
                var node = _base.ChildNodes.Cast<XmlNode>().FirstOrDefault(x => x.Name == "ARRAY-SIZE-SEMANTICS");
                if (node != null) return node.InnerText; else return "";
            }
        }
    }

    class NodeCollections : IEnumerable<Node>, IEnumerator<Node>, IEnumerator
    {
        private XmlNode _base;

        private XmlNode _itl;

        public NodeCollections(XmlNode basenode)
        {
            _base = basenode;
            Reset();
        }

        public IEnumerator<Node> GetEnumerator()
        {
            return this;
        }

        IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this;
        }

        public Node Current
        {
            get { return new Node(_itl); }
        }

        public void Dispose()
        {
            //throw new NotImplementedException();
        }

        object IEnumerator.Current
        {
            get { return Current; }
        }

        public bool MoveNext()
        {
            if (_base == null) return false;
            if (_itl == null && _base.FirstChild != null)
            {
                _itl = _base.FirstChild;
                return true;
            }
            if (_itl.NextSibling != null)
            {
                _itl = _itl.NextSibling;
                return true;
            }
            return false;
        }

        public void Reset()
        {
            _itl = null;
        }
    }

    class DGVItem
    {
        public string shortname { get; set; }
        public string category { get; set; }
        public string shortname1 { get; set; }
        public string category1 { get; set; }
        public string arraysize { get; set; }
        public string arraysizesemantic { get; set; }
        public string basetyperef { get; set; }
    }
}

大概看了下
public NodeCollections Children
{
get
{
var sub = _base.ChildNodes.Cast().FirstOrDefault(x => x.Name == "SUB-ELEMENTS");
if (sub == null)
sub = _base.ChildNodes.Cast().FirstOrDefault(x => x.Name == "ELEMENTS");
return new NodeCollections(sub);
}
}
如果你要加载Tuner,这里要加上EVENTS
if (sub == null)
sub = _base.ChildNodes.Cast().FirstOrDefault(x => x.Name == "EVENTS");
就写在Children的subelements后面

ccc9149
未知昵称 caozhy 大佬人不在吗??求解决bug。
大约一年之前 回复
ccc9149
未知昵称 添加methods的时候,因为methods下也嵌套了子节点,错误提示见下面的图
大约一年之前 回复
ccc9149
未知昵称 看下面的图片,events这样写 没问题。加载methdos内容,想把子节点内容显示在datagridview中,代码跳到421行有问题
大约一年之前 回复
ccc9149
未知昵称 我是Tuner下面的events 和 methods都可以加载在treeview中,我尝试可以在datagridview中加载events节点下内容,但是尝试想在datagridview中加载methods节点内容,但是代码307行我自己写的,有问题。
大约一年之前 回复

图片说明 @caozhy

图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
C#读取xml文件数据。显示在datagridview控件
[之前提的问题,自己修改,有bug](https://ask.csdn.net/questions/695201 "")rnrnrn具体bug提示,描述,见上述链接问题的最后面的评论。rnrn现在需要在datagridview中,显示Tuner下面的节点METHODS下面的子节点内容。rn之前回复问题的牛人还在吗?rnrn问题代码在之前的问题中有下载链接rnrnrnrn![图片说明](https://img-ask.csdn.net/upload/201807/25/1532482153_316607.png)
C#读取XML文件数据显示在datagridview控件中
![图片说明](https://img-ask.csdn.net/upload/201807/12/1531375980_853491.png)nnnn如上图所示,读取XML文件中某个节点下的内容,累计叠加显示到datagridview,这一块代码怎么写??nnn![图片说明](https://img-ask.csdn.net/upload/201807/12/1531376253_103237.png)nn n n
Q695201 问答问题的回答 C#读取xml文件数据。显示在datagridview控件问题
Q695201 问答问题的回答 https://ask.csdn.net/questions/695201 C#读取xml文件数据。显示在datagridview控件问题
datagridview控件显示数据
我采用的是odbc连接数据库,在copytableBindingSource中能预览数据,datagridview控件也绑定好的数据,在设计器中也正常显示数据库中表的列名,但是程序运行就显示不出数据了rnrn请问怎么解决这个问题,谢谢~
读取Xml文件,ListView控件显示
   private void FrmOrderTicketInfo_Load(object sender, EventArgs e)         {             lvBuyTicketInfo.Items.Clear();//清空lisvView             // lvMovieInfo.View = View.Tile;           ...
ajax读取显示xml文件数据
我想利用循环把data.xml文件数据读出rnrnrn rn 1rn hljrn 2001年rn ztrn rn rn 2rn hebrn 2002年rn tyhrn rnrnrn我写的AJAX文件为什么不对?rn rnrnrnrn rnrnrnrnrn在线等待,谢谢!
C#读取TXT文件在dataGridView显示。
以下是文件内容由空格分开rn0 170.4917 1.7194 0 170.5166 3.3402 0 171.7997 2.1545 0 168.2972 2.1565 0 164.7947 2.1586 rn0 161.2921 2.1606 0 157.7896 2.1627 0 154.2871 2.1647 0 150.7846 2.1668 0 147.2821 2.1688 rn0 143.7796 2.1708 0 140.2770 2.1729 0 136.7745 2.1749 0 133.2720 2.1770 0 129.7695 2.1790 rn0 126.2670 2.1811 0 122.7645 2.1831 0 119.2619 2.1852 0 115.7594 2.1872 0 112.2569 2.1892 rn0 108.7544 2.1913 0 105.2519 2.1933 0 101.7493 2.1954 0 98.2468 2.1974 0 94.7443 2.1995 rn0 91.2418 2.2015 0 87.7393 2.2035 0 84.2368 2.2056 0 80.7342 2.2076 0 77.2317 2.2097 rn0 73.7292 2.2117 0 70.2267 2.2138 0 66.7242 2.2158 0 63.2216 2.2178 0 59.7191 2.2199 rn0 56.2166 2.2219 0 52.7141 2.2240 0 49.2116 2.2260 0 45.7091 2.2281 0 45.7389 5.4404 rn0 49.2279 5.4324 0 52.7170 5.4245 0 56.2061 5.4166 0 59.6952 5.4086 0 63.1843 5.4007 rn0 66.6734 5.3927 0 70.1624 5.3848 0 73.6515 5.3769 0 77.1406 5.3689 0 80.6297 5.3610 rn0 84.1188 5.3531 0 87.6078 5.3451 0 91.0969 5.3372 0 94.5860 5.3292 0 98.0751 5.3213 rn0 101.5642 5.3134 0 105.0533 5.3054 0 108.5423 5.2975 0 112.0314 5.2896 0 115.5205 5.2816 rn0 119.0096 5.2737 0 122.4987 5.2657 0 125.9878 5.2578 0 129.4768 5.2499 0 132.9659 5.2419 rn0 136.4550 5.2340 0 139.9441 5.2260 0 143.4331 5.2181 0 146.9222 5.2102 0 150.4113 5.2022 rn0 153.9004 5.1943 0 157.3894 5.1864 0 160.8785 5.1784 0 164.3676 5.1705 0 167.8567 5.1625 rn0 171.3457 5.1546 0 171.3869 8.5029 0 167.8845 8.5038 0 164.3821 8.5047 0 160.8797 8.5055 rn0 157.3773 8.5064 0 153.8748 8.5073 0 150.3724 8.5082 0 146.8700 8.5091 0 143.3676 8.5099 rn0 139.8652 8.5108 0 136.3628 8.5117 0 132.8604 8.5126 0 129.3580 8.5135 0 125.8556 8.5143 rn0 122.3531 8.5152 0 118.8507 8.5161 0 115.3483 8.5170 0 111.8459 8.5179 0 108.3435 8.5187 rn0 104.8411 8.5196 0 101.3387 8.5205 0 97.8363 8.5214 0 94.3339 8.5223 0 90.8315 8.5231 rn0 87.3290 8.5240 0 83.8266 8.5249 0 80.3242 8.5258 0 76.8218 8.5267 0 73.3194 8.5275 rn0 69.8170 8.5284 0 66.3146 8.5293 0 62.8122 8.5302 0 59.3098 8.5311 0 55.8073 8.5319 rn0 52.3049 8.5328 0 48.8025 8.5337 0 48.8619 5.4999 0 55.4986 1.4660 0 55.7810 4.3382 rn0 56.0635 7.2105 0 56.3459 10.0827 0 56.3968 7.2099 0 56.4477 4.3372 0 56.4985 1.4644 rn0 56.7797 4.3363 0 57.0608 7.2082 0 57.3419 10.0802 0 57.3941 7.2077 0 57.4463 4.3352 rn0 57.4985 1.4627 0 57.7783 4.3344 0 58.0581 7.2060 0 58.3379 10.0777 0 58.3914 7.2055 rn0 58.4450 4.3333 0 58.4985 1.4611 0 58.7770 4.3325 0 59.0554 7.2038 0 59.3339 10.0751 rn0 59.3888 7.2033 0 59.4436 4.3314 0 59.4985 1.4595 0 59.7756 4.3305 0 60.0528 7.2016 rn0 60.3299 10.0726 0 60.3861 7.2010 0 60.4423 4.3294 0 60.4985 1.4578 0 60.7743 4.3286 rn0 61.0501 7.1994 0 61.3259 10.0701 0 61.3834 7.1988 0 61.4409 4.3275 0 61.4985 1.4562 rn0 61.7729 4.3267 0 62.0474 7.1971 0 62.3219 10.0676 0 62.3807 7.1966 0 62.4396 4.3256 rn0 62.4984 1.4546 0 62.7716 4.3247 0 63.0447 7.1949 0 63.3179 10.0651 0 63.3781 7.1944 rn0 63.4382 4.3237 0 63.4984 1.4529 0 63.7702 4.3228 0 64.0421 7.1927 0 64.3139 10.0626 rn0 64.3754 7.1922 0 64.4369 4.3217 0 64.4984 1.4513 0 64.7689 4.3209 0 65.0394 7.1905 rn0 65.3099 10.0601 0 65.3727 7.1899 0 65.4356 4.3198 0 65.4984 1.4497 0 65.7675 4.3190 rn0 66.0367 7.1883 0 66.3058 10.0576 0 66.3700 7.1877 0 66.4342 4.3179 0 66.4984 1.4480 rn0 66.7662 4.3170 0 67.0340 7.1860 0 67.3018 10.0550 0 67.3674 7.1855 0 67.4329 4.3159 rn0 67.4984 1.4464 0 67.7649 4.3151 0 68.0313 7.1838 0 68.2978 10.0525 0 68.3647 7.1833 rn0 68.4315 4.3140 0 68.4983 1.4448 0 68.7635 4.3132 0 69.0287 7.1816 0 69.2938 10.0500 rn0 69.3620 7.1810 0 69.4302 4.3121 0 69.4983 1.4431 0 69.7622 4.3112 0 70.0260 7.1794 rn0 70.2898 10.0475 0 70.3593 7.1788 0 70.4288 4.3102 0 70.4983 1.4415 0 70.7608 4.3093 rn0 71.0233 7.1771 0 71.2858 10.0450 0 71.3566 7.1766 0 71.4275 4.3082 0 71.4983 1.4398 rn0 71.7595 4.3074 0 72.0206 7.1749 0 72.2818 10.0425 0 72.3540 7.1744 0 72.4261 4.3063 rnrn需要以下面的格式输入rn0 170.4917 1.7194 rn0 170.5166 3.3402 rn 0 171.7997 2.1545rn 0 168.2972 2.1565rn 0 164.7947 2.1586 rn0 161.2921 2.1606rn 0 157.7896 2.1627 rn0 154.2871 2.1647rn 0 150.7846 2.1668rn 0 147.2821 2.1688 rn。。。。。。。。rn
读取xml文件到DataGridView,怎么修改数据?
[code=csharp]rn string id = strArr[0];rn dateTimePicker1.Value = Convert.ToDateTime(strArr[1]);rn deptidText.Text = strArr[2];rn emplidText.Text = strArr[3];rn nameText.Text = strArr[4];rn comboBox1.Text = strArr[5];rn timeText.Text = strArr[6];rn remarkText.Text = strArr[7];rn[/code]rn数据我都取到了,为了修改对,我专门设了自增的id。rn我想过先删除在插入,但是,那样就变成最后一条了
C#读取XML文件的问题
XML内容如下rn[code=XML]rnrn1rn0rn0 rnrnrnrntruern0rnrnrn1rn0rn1rnrn新闻rnrntruern52428rnrn[/code]rnrn想得到字符串“新闻”,使用SelectSingleNode方法出错。有解决的办法吗?rnrn难道不算node吗?
C#读取XML文件问题
各位大佬,今天遇到一个问题,我在winform程序里通过XmlDocument加载一个XML文件,然后周期性的向里面写新的值,每次写完都调用save进行保存,这样发现XML文件的内容是可以被更新的。rn但是我另一个程序也加载了这个XML文档,然后读取里面的值,此时发现读取出来的值一直都是第一次读取出来的值,请问这是什么原因,感觉就像是第一次读取后做成了一个副本,然后这个副本却不更新。rn我用XmlDocument对象的NodeChanged事件测试了下,只有我手动更改第一次获取的节点的值时会触发事件,另一个程序更新节点值不会触发。rn期待各位大佬的解答!!!
c#读取xml文件的问题~~
将select中的txt文件(数据表名)读取为filename再通过数据库将txt中的表名通过writexml导出rn但是现在select语句中的filename一直显示有问题,不知如何修改。。。。。rn[code=csharp][/code]rn private void exportData1(object sender, EventArgs e)rn rnrn string[] aa = new string[10];rn rn FileStream fs = new FileStream("c:\\select.txt", FileMode.Open);rn StreamReader m_streamReader = new StreamReader(fs);rn m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);rn string strLine = m_streamReader.ReadLine();rn int shu = 0;rn dorn string[] split = strLine.Split('\n');rn aa[shu] = strLine;rn shu++;rn strLine = m_streamReader.ReadLine();rn string filename = aa[shu];rn String strCon = "Data Source=XXJSB-PC;Initial Catalog=master;Integrated Security=True";rn SqlConnection con = new SqlConnection(strCon);rn con.Open();rn SqlDataAdapter da = new SqlDataAdapter("select * from " +filename+ "", con);rn DataSet ds = new DataSet();rn da.Fill(ds);rn ds.WriteXml(filename);rn con.Close();rn rn while (strLine != null);rn m_streamReader.Close();rn m_streamReader.Dispose();rn fs.Close();rn fs.Dispose();rn rn rn rn
C#读取XML文件问题?
[code=XML]rnrn rn 错误的详细描述 rn 用于定位的信息rn rn rn 错误的详细描述 rn 用于定位的信息rn rn rn 错误的详细描述 rn 用于定位的信息rn rn rn 错误的详细描述 rn 用于定位的信息rn rn[/code]rn怎样使用XmlReader将上面的XML文件的读取到一个下面结构的DataTable或者Listrnrntool defectname filename function line serious status message detail loactionrn最好还可以读取一部分,比如先读前面两条,下次需要读取后面两条
读取xml文件数据问题
如:rnrn rnrnrn我用: Dim ac As XmlAttributeCollection = node.Attributesrnac.GetNamedItem("ChannelCode").Value获取不到ChannelCode的值(try catch报错说给定编码中的字符无效),如果把"力"改为"load",就一点问题都没有,各位高手,这是怎么回事啊。
c#读取xml文件问题
xml文件内容如下:rn[code=XML]rnrnrn rn 我的青春谁做主rn youkurn rn 第1集rn 第2集rn 第3集rn 第4集rn 第5集rn 第6集rn rn rn rn 我的青春谁做主rn youkurn rn 第1集rn 第2集rn 第3集rn 第4集rn 第5集rn 第6集rn rn rn rn 我的青春谁做主rn youkurn rn 第1集rn 第2集rn 第3集rn 第4集rn 第5集rn 第6集rn rn rnrn[/code]rnrn如何在winform中,将数据显示在treeView控件里?详细代码怎么写?谢谢!
C# 读取xml文件的问题
c#怎么把xml文件里所有的字符都读出来,包括头部代码!rn谢谢
C#读取xml文件C#读取xml文件
xmlread程序xmlread程序xmlread程序xmlread程序xmlread程序
C#读取Xml文件 C#读取Xml文件
C#读取Xml文件C#读取Xml文件C#读取Xml文件C#读取Xml文件
C#读取xml文件节点数据问题
![图片说明](https://img-ask.csdn.net/upload/201807/11/1531293524_683244.png)nnnn如上图所示,我要读取到ELEMNTS节点下的子节点内容,例如读取第一个子节点所有内容,代码怎么写呢?nnuint8nnVALUEnn/DataTypes/BaseTypes/uint8nnnnn如果单独读取到nn/DataTypes/BaseTypes/uint8nn这个内容怎么写?nnnnnnnnnnnn[xml文件下载地址](https://pan.baidu.com/s/1IduPYubieI1Z1wnMsWnobA "")
datagridview控件 数据重复显示
[code=C#]rn private void btnSearch_Click(object sender, EventArgs e)rn rn rn rn if (validateInput())rn rn rn string sql=string.Format("select c.invCode,i.cInvName,i.cInvStd,i.cComUnitName,c.BaseQtyN,c.BaseQtyD,i.cDefWareHouse,i.cWhName,i.cInvCname,c.loc,i.iInvNcost from bom_child as c inner join Inventorys as i on c.invCode=i.cInvCode where bomid=(select bomid from bom_parents where invCode='0' and version='1')",txtParentCode.Text,cboBomVersion.Text);rn tryrn rn rn dataAdapter = new SqlDataAdapter(sql, DBHelp.connection);rnrn dataAdapter.Fill(dataSet, "child");rnrn dgvChild.DataSource = dataSet.Tables["child"];rn rn rn catch (Exception ex)rn rn MessageBox.Show(ex.Message);rn rn finallyrn rn DBHelp.connection.Close();rn rn rn rn rn rn[/code]rn代码如上图所示rnrn第一次点击按钮是正确的,但是第二次点击按钮,在dgvChild(datagridview)控件中,会把两次的结果都显示出来。rnrn我猜测是应该是 dataset.table 和 datagridview里的行没有清空吧,这个要怎么处理呢?rn我在rndgvChild.DataSource = dataSet.Tables["child"];rn后面加了一条rndataSet.Tables["child"].Clear();rnrn但是这样,数据根本就不显示了。rn
在Datagridview控件显示Datatable数据
欢迎使用Markdown编辑器写博客 本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和图片上传 LaTex数学公式 UML序列图和流程图 离线写博客 导入导出Markdown文件 丰富的快捷键 快捷键 加粗 Ctrl + B 斜体 Ctrl + I...
C#数据Datagridview控件实用
很全的datagridview控件大全,本人亲测,用法简单。
C#中dataGridView显示数据
[size=18px][在VS2008的wiform下.rn我用dataGridView显示数据,有好几个列的数据是数字型的,rn比如第一列的"0",或"1",我想依照这个数字,0故障,1正常,rn第二列的"0",或"1",我想依照这个数字,0无效,1有效,rn这个dataGridView我是用table绑定的rnthis.dataGridViewzhuijia.DataSource = table;[/size]rn[img=file:///C:/Documents%20and%20Settings/Administrator/桌面/QQ截图未命名.jpg][/img]rnrnrnrn请问大家这个该怎么做呢
C# datagridview 数据重复显示
[img=https://img-bbs.csdn.net/upload/201507/13/1436796563_589107.png][/img][img=https://img-bbs.csdn.net/upload/201507/13/1436796584_956936.png][/img]rn显示的datagridview是重复的,也百度了好多解决方法,但是都没能解决,求大神指教!!
C# datagridview显示access数据
初学C#求dataGridView的基本用法 谢谢rn OleDbConnection connection1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:\\db1.mdb");rn DataSet ds;rn private void FormSCScoreManage_Load(object sender, EventArgs e)rn rn rn connection1.Open();rn string sql = "select Student_ID as 学号,Student_Nam as 姓名,Student_Sex as 性别,Student_Age as 年龄,Student_Spe as 专业,Student-DParty as 所在系 from StudentInfo";rn OleDbDataAdapter adp = new OleDbDataAdapter(sql, connection1);rn ds = new DataSet();rn adp.Fill(ds, "Student");rn dataGridView1.DataSource = ds;rn dataGridView1.DataSource = ds.Tables[0].DefaultView;rn rn rn运行后在dataGridView中没有显示想要的内容,求高手指点。
怎么用datagridview读取XML文件
求高手解答
datagridview数据显示问题
SqlConnection con = DB.createConn();rn SqlCommand cmd = con.CreateCommand();rn cmd.CommandType = CommandType.StoredProcedure;rn cmd.CommandText = "train_no";rn cmd.Parameters.Add( "@tr_no",SqlDbType.VarChar,8).Value=train_no;//train_no已经赋值rn dataGridView1.DataSource = bindingSource1;rn GetDate(cmd.CommandText); rn报错,存储过程参数没有提供。rnpublic void GetDate(string sqlCmd)rn rn SqlConnection conn=DB.createConn();rn SqlDataAdapter sda=new SqlDataAdapter (sqlCmd,conn);rn SqlCommandBuilder cmdbuilder=new SqlCommandBuilder (sda);rn DataTable tb=new DataTable ();rn //获取或设置用于比较表中字符串的区域设置信息rn tb.Locale=System.Globalization.CultureInfo.InvariantCulture;rn sda.Fill(tb);rn bindingSource1.DataSource=tb;rn dataGridView1.AutoResizeColumns(rn DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);rn rn当sqlcmd是SQL查询语句时,成功运行。rn当是存储过程时,报错:“过程或函数 'train_no' 需要参数 '@tr_no',但未提供该参数”。rnrnrnrn
dataGridView的显示数据问题
我写了以下的代码,目的是想要筛选需要的数据,其它的链接等都没有问题了。其中还有一个textbox ,我要在其中输入相应的内容,例如输入队员编号为:1003.请问我要怎么做才能让datagridview1中显示的内容是我要查询的内容(即队员编号为1003的队员的资料)? 愿赐教! rn if( comboBox1 .Text =="队员编号")rn rn DataSet ds = new DataSet();rn string sql = @"select * from worker_table ";rn SqlDataAdapter sdal = new SqlDataAdapter(sql ,conn);rn sdal .Fill (ds ,"tb1" );rn rn BindingSource bs = new BindingSource();rn bs.DataMember = "tb1";rn bs.DataSource = ds ;rn this.dataGridView1.DataSource = bs;rn
C# dataGridView控件的问题
[img=https://img-bbs.csdn.net/upload/201401/03/1388715144_706013.jpg][/img]rn为什么1处会多一行,2处的滚动条没有
Winform DataGridView控件显示数据慢的问题
我的数据库中有数据大概300条左右,我用DataSet 直接绑定DataGridView,在查所有数据的时候显示非常慢,慢到一行一行的显示出来,在拖动滚动条的时候很卡,求高手解决办法
datagridview 数据显示的问题
[img=https://img-bbs.csdn.net/upload/201306/24/1372068657_538339.jpg][/img]rnrn我在datagridview 中做了一个查询数据的功能 用他来显示出来 但每次查询都会在原来哪一行中增加一行 如图片所示 代码如下rn[code=csharp]//绑定数据的方法rn private void GetDB(string str)rn rn //SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");rn //con.Open();rn //SqlDataAdapter sdr = new SqlDataAdapter();rn //SqlCommand cmd = new SqlCommand(str, con);rn //sdr.SelectCommand = cmd;rn //DataSet ds = new DataSet();rn con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");rn con.Open();rn sdr = new SqlDataAdapter();rn sdb = new SqlCommandBuilder(sdr);rn cmd = new SqlCommand(str,con);rn sdr.SelectCommand = cmd;rn ds = new DataSet();rn sdr.Fill(ds);rn //向gridview中添加列rn DataGridViewTextBoxColumn col_txb_Id = new DataGridViewTextBoxColumn();rn col_txb_Id.HeaderText = "课程编号";rn col_txb_Id.DataPropertyName = "cno";rn dataGridView1.Columns.Add(col_txb_Id);rnrn DataGridViewTextBoxColumn col_txb_Name = new DataGridViewTextBoxColumn();rn col_txb_Name.HeaderText = "课程名";rn col_txb_Name.DataPropertyName = "cname";rn dataGridView1.Columns.Add(col_txb_Name);rnrn DataGridViewTextBoxColumn col_txb_Score = new DataGridViewTextBoxColumn();rn col_txb_Score.HeaderText = "课程学分";rn col_txb_Score.DataPropertyName = "ccredit";rn dataGridView1.Columns.Add(col_txb_Score);rnrn DataGridViewButtonColumn col_btn_state = new DataGridViewButtonColumn();rn col_btn_state.HeaderText = "删除";rn col_btn_state.Text = "删除";rn col_btn_state.UseColumnTextForButtonValue = true;rn dataGridView1.Columns.Add(col_btn_state);rnrn DataGridViewButtonColumn col_btn_update = new DataGridViewButtonColumn();rn col_btn_update.HeaderText = "修改";rn col_btn_update.Text = "修改";rn col_btn_update.UseColumnTextForButtonValue = true;rn dataGridView1.Columns.Add(col_btn_update);rnrn DataGridViewButtonColumn col_btn_insert = new DataGridViewButtonColumn();rn col_btn_insert.HeaderText = "增加";rn col_btn_insert.Text = "增加";rn col_btn_insert.UseColumnTextForButtonValue = true;rn dataGridView1.Columns.Add(col_btn_insert);rn this.dataGridView1.DataSource = ds.Tables[0];rn con.Close();rn [/code]rnrn[code=csharp]//查询功能代码rn private void button1_Click(object sender, EventArgs e)rn rn SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=StuManage;Integrated Security=True");rn con.Open();rnrn if(comboBox1.Text=="课程名")rn rn string str = "select * from tb_course where cname='" + textBox1.Text.Trim() + "'";rn GetDB(str);rn rnrn rn if (comboBox1.Text == "课程编号")rn rn string str="select * from tb_course where cno='" + textBox1.Text.Trim() + "'";rn GetDB(str);rn rn rn if(comboBox1.Text=="" || textBox1.Text=="")rn rn rn MessageBox.Show("请选择查询的方式并且在输入框中输入相应的查询信息","查询提示");rn return;rn rn rn [/code]rnrn能不能告诉我是什么原因 或是否可以设置datagridview的属性 让数据正常显示 而不是像图片中显示那样
dataGridView 显示数据的问题
rn各位大哥,这是用CS结构写的,所以没有dataGridview1.DataBind();的说法哦. rnrn看下面的写法rndataGridView怎么不能用command.ExecuteReader()读出数据呢,问题出在那啦rnrnrn SqlConnection conn = ConDB.CreateConnection();rn conn.Open();rn SqlCommand command = new SqlCommand("select * from test",conn);rn this.dataGridView1.DataSource = command.ExecuteReader();rn conn.Close();rnrn
datagridview 数据显示问题
我用vb2005.。汇总,在datagridview显示rnsqlstr = "select 工种,sum(定额工时) as 总定额工时,sum(实用工时) as 总实用工时 from 输入表 where 日期 >= '" & d1 & " ' And 日期 <= '" & d2 & "' group by 工种"rnrnrn但是汇总后。总定额工时和总实用工时,小数点好多位,怎么才能取两位啊
DataGridView数据显示的问题
我现在写一个应用程序 有很多个窗体可供用户进行选择 还有一个窗体是显示用户选择的数据的 用户在不同的窗体中进行数据的选择 然后打开已选的窗体 如何让用户在不同的窗体中所选的数据全部显示在已选窗体的DataGridView中
datagridview显示数据问题
请问各位大虾:rn如何使数据表能够完全填充datagridviewrn也就是数据表里面的字段以及字段值都显示在datagridview上,并且要完全填充rn如果使用这段代码:dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; rn只是在datagridview上的左上角显示了所有的数据,其他区域并没被填充到rn怎样才能实现不管datagridview有多大,都能使要显示的数据完全填充rn不知道,我叙述的清楚不rn各位大虾们,帮帮忙忙~~~rnrnrn
dataGridView显示数据的问题
string myConStr = "Provider = Microsoft.Jet.OLEDB.4.0;";rn myConStr += "Data Source = Mydata.mdb;";rn OleDbConnection myCon = new OleDbConnection(myConStr);rn myCon.Open();rn string StrSQL = "select * from data where title like '%@title%'";rn OleDbDataAdapter da = new OleDbDataAdapter(StrSQL, myCon);rn da.SelectCommand.Parameters.AddWithValue("@title", textBox_title.Text);rn DataTable dt = new DataTable();rn da.Fill(dt);rn this.dataGridView1.DataSource = dt;rn myCon.Close();rn执行后dataGridView1什么都没有显示,高手帮忙看下哪错了~谢了
dataGridView数据显示问题
绑定数据源rn dgvRoom.DataSource= RoomTypeManager.GetAllRoom();rn //RoomTypeManager.GetAllRoom();返回的是一个List集合rn rnrn 要怎么设置才能选择显示数据源中的数据?rn
datagridview 显示数据问题。。。
datagridview 显示数据问题后 rn 我要对每行数据进行 更新或着是 删除等操作 我怎么获取是选中了 数据库的哪一行数据rn 例如 要知道他的 ID
c# 窗体中DATAGRIDVIEW控件显示问题
[img=http://img.pconline.com.cn/images/bbs4/200910/14/1255487523334.jpg][/img]rnrn各位好,在使用GRIDVIEW控件时程序中插入行列后显示的表格总是有如图红圈所示的已选择块,有没办法消除. rn
C# DataGridView显示问题
[img=http://img.my.csdn.net/uploads/201211/03/1351947175_8706.jpg][/img]rnrn请问如何处理图片红框部份,rn这部份是否可以固定大小,默认好像可以手工拉大。
c# 关于DataGridView数据显示的问题
我有一个表的数据如下:rnt1 t2 rn01 aa rn02 bbrn01 ccrn03 ddrn在数据显示的时候,当t1=01时,显示 课程1,t2=02的时候显示 课程2,应该怎么样显示?
相关热词 c#检测非法字符 c#双屏截图 c#中怎么关闭线程 c# 显示服务器上的图片 api嵌入窗口 c# c# 控制网页 c# encrypt c#微信网页版登录 c# login 居中 c# 考试软件