I have edit a few items in my comboBox1 on my Form.
The items in the comboBox exists of dates like this

2000/01/01
2001/01/01

So these 2 dates can be selected from the comboBox.
I am doing a calculation with the selected date in the comboBox1. This works without
any problem.

If I write the date: 2001/01/01 manually instead of choosing ex: the date: 2001/01/01 in the comboBox1 and press my button that do the calculation, it comes up an errormessage.
"Unhandled exception has occured in your application" etc...

Why is this happening, what is the difference. I am not putting any blankspaces when I write manually. It is identical 100 % ?

I am get the contents from the comboBox1 like this:

String^ Date1;
Date1 = comboBox2->SelectedItem->ToString();

Should you check that the SelectedItem is not a null reference.

I beleive as long as this Error Message comes up, it has to be a NULL reference, so if I check it, that will meen that I have to choose an item from the comboBox1 anyway in the end.
I think that is the problem anyway.

I am not sure if comboBox only works to read from and not write in like the textBox ?

Should you check that the SelectedItem is not a null reference.

I found a solution. If you change:

Date1 = comboBox2->SelectedItem->ToString();

to

Date1 = comboBox2->Text->ToString();

Then it will work. So using Text instead of Items.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.