c# - WPF UserControl throws NullReferenceException when loading -
i have wpf project main window , usercontrol.
in usercontrol set gridcontrol.itemssource using gridcontrol.itemssource = query.tolist(), when loading usercontrol throws exception:
"the object reference not set object"
in spite of query returning 40 rows of data.
the code executed in mainwindow usercontrol throws exception.
consolidating conversation comments on question:
a nullreferenceexception thrown on line
gridcontrol.itemssource = query.tolist(); as gridcontrol null.
for more information on exception see what nullreferenceexception, , how fix it?
i'm guessing line in question before call initializecomponent() in constructor.
this method initialises of controls in usercontrol. therefore, if trying use control before call method, throw nullreferenceexception.
what want see is:
public yourusercontrol() { initializecomponent(); gridcontrol.itemssource = query.tolist(); }
Comments
Post a Comment