Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
TimeSpan TimeSpan = DateTime.Now.Subtract( dropDown.LastClosedTimeStamp );

parmp.popupComboBox.Items.Add("ALL");
parmp.popupComboBox.Visible = true;
parmp.popupComboBox.Show();

An unhandled exception of type
'System.NullReferenceException' occurred in CheckBoxComboBox.dll

I get this error whenever I first click on a newly created and displayed PopupComboBox.

It appears that for some reason the lastClosedTimeStamp is never initialized because the component has never been shown, and when I click on it. It blows up. The Demo works well, it just does not work when I added the CheckBoxComboBox folder into my Solution and then place the component on inside a custom control (custom control contains a panel and on top of this panel I place the CheckBoxComboBox) when custom control is created and displaying the CheckBoxComboBox, I click on it then I get that error.

Please help.
Thank you,

What I have tried:

It appears that for some reason the lastClosedTimeStamp is never initialized because the component has never been shown, and when I click on it. It blows up. The Demo works well, it just does not work when I added the CheckBoxComboBox folder into my Solution and then place the component on inside a custom control (custom control contains a panel and on top of this panel I place the CheckBoxComboBox) when custom control is created and displaying the CheckBoxComboBox, I click on it then I get that error.
Posted
Updated 14-Apr-16 7:00am
Comments
an0ther1 11-Apr-16 21:09pm    
I would suggest that the LastClosedTimeStamp is NULL, therefore it cannot be converted to a DateTime value.
Use your debugger & check what the value of the LastClosedTimeStamp property is, if it is null then don't try to convert it.

Kind Regards

The name of the property indicates that it returns the datetime when the control has been closed the last time. It seems that null is returned when this has not happend so far. So you must catch that condition in your code:
C#
// Use zero time span when dropDown does not exist or
//  dropDown.LastClosedTimeStamp not set.
TimeSpan span = new TimeSpan(0, 0, 0);
if (dropDown != null && dropDown.LastClosedTimeStamp != null)
    span = DateTime.Now.Subtract( dropDown.LastClosedTimeStamp );

To check this condition afterwards, you may then use the TimeSpan.Zero property.
 
Share this answer
 
You need to contact whoever made the control you are using and have them modify the source code to fix this issue.
 
Share this answer
 
I fixed the problem by including a reference to the CheckBoxComboBox.dll into my project references, instead of including the whole project into the solution. That fixed it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900