日期:2014-05-16  浏览次数:20810 次

急!!(新手)winform DataGridView 加载XML,行数显示正确,但是内容没有
DataGridView加载XML问题
我的DataGridView是手动添加的固定列(5列,最后一个按钮列,固定的),DataSet中的dt也设置了4个字段one,two,thr,fou,代码如下
XmlDocument xml = new XmlDocument();
xml.Load("./Xml.xml");
XmlNode node = xml.SelectSingleNode("NewDataSet");

foreach (XmlNode xnode in node.SelectNodes("Table"))
{
     DataRow row = this.dt.NewRow();
   foreach (XmlNode xcnode in xnode.ChildNodes)
     {
        //xML里很多字段,我只取这四个
         if (xcnode.Name == "one" || xcnode.Name == "two" || xcnode.Name == "thr" || xcnode.Name == "fou")
             row[xcnode.Name] = xcnode.InnerText;
      }
      //添加该数据行
     this.dt.Rows.Add(row);
  }
  this.m_dgv.AutoGenerateColumns = true;
   this.m_dgv.DataSource = ds;
   this.m_dgv.DataMember = ds.Tables[0].TableName;
int count = this.m_dgv.Rows.Count; //等于10
  string str = this.m_dgv.Rows[0].Cells[0].Value.ToString(); //报错“未将对象引用设置到对象的实例



界面显示不了数据,行数已经有了(XML中有10条数据)。初次接触,请大神指点,分数不多了,请多多包含
------解决方案--------------------

 DataSet dds = new DataSet();           
            dds.ReadXml("Xml.xml");
            this.m_dgv.DataSource = dds.Tables[0].DefaultView;