当设置数据源的DataGridView错误 [英] DataGridView error when set DataSource

查看:163
本文介绍了当设置数据源的DataGridView错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误运行datagridview.DataSource =数据视图时; 数据视图是正确的。我可以看到里面的数据,当我调试程序。

I got an error when run datagridview.DataSource = dataView; dataview is correct. I can see data inside it when I debug program.

我得到一个错误不设置到对象的实例对象引用。

I got next error "Object reference not set to an instance of an object."

任何想法?

code:

this.datagridview = new System.Windows.Forms.DataGridView();

...

  DataSet ds = new DataSet();
  XmlReaderSettings settings = new XmlReaderSettings();
  StringReader stringReader = new StringReader(retString);
  XmlReader xmlReader = XmlReader.Create(stringReader, settings);
  ds.ReadXml(xmlReader);
  DataView dataView = ds.Tables[0].DefaultView;

数据视图不为空。我调试的时候我能够查看

dataView is not null. I am able to view it when debug

推荐答案

是你code中相同的方法,或者是的DataGridView的初始化的一个的InitializeComponent 的方法?

Is all you code in the same method, or is the initialization of the DataGridView in a InitializeComponent method?

如果它在一个的InitializeComponent 方法,请确保您的其他code被称为后该方法被调用。检查,如果你已经有了一个构造你的控制它调用的InitializeComponent

If it's in a InitializeComponent method, make sure that your other code is called after that method has been called. Check that if you've got a constructor for your Control that it calls InitializeComponent.

这篇关于当设置数据源的DataGridView错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆