开发者

DataGridView error when set DataSource

开发者 https://www.devze.com 2022-12-30 20:58 出处:网络
I got an error when run datagridview.DataSource = dataView; dataview is correct. I can see data inside it when I debug program.

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."

Any Ideas?

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(stringRead开发者_如何转开发er, settings);
  ds.ReadXml(xmlReader);
  DataView dataView = ds.Tables[0].DefaultView;

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


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

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.


This means that the datagridview variable is null.

0

精彩评论

暂无评论...
验证码 换一张
取 消