views:

70

answers:

2

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(stringReader, settings);
  ds.ReadXml(xmlReader);
  DataView dataView = ds.Tables[0].DefaultView;

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

A: 

This means that the datagridview variable is null.

SLaks
I edit question. See code lines.
It still means that the `datagridview` field is `null`. Where is this code? Can you check `datagridview` in the debugger?
SLaks
A: 

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.

ho1