I have a ComboBox that fills up at the touch of a button. One click - one fill. I need that on each press there is a reconciliation of the current element with all the previous ones, so that there are no repetitions. I decided to try this check:

 for (int i = 0; i < comboBox1->Items->Count; i++) if (System::Convert::ToDouble(comboBox1->Items[i]) != x2) comboBox1->Items->Add(System::Convert::ToString(x2)); 

Without verification, the filling goes with a bang, but the elements can be repeated. This code refuses to work. That is, compile errors do not pop up, but the check is not performed. Tell me, please, how it would be possible to correct the condition to make it work.

  • one
    some kind of nightmare, did it not occur to you to add values ​​to the vector and check it, and then update / not update the interface without these creepy checks and castes in the loop? Olso, for loops and hypotheses without curly brackets, hands must be torn off - strangeqargo
  • one
    @strangeqargo It would come if I could use them. I'm just starting to learn a language - so I use what I know. I use braces only if there is more than one command. For the rest, I do not see the point. Perhaps later corrected. - PavelKas
  • @PavelKas will have to disappoint you. You are learning the wrong language, i.e. This is not C ++, but C ++ / CLI - a hand-made article from MS for the .Net infrastructure, for a managed environment. - αλεχολυτ
  • The code does not understand what x2 and where it is installed. Try to give a so-called minimal reproducible example . In general, the likely problem is that you compare floating-point numbers through != . - αλεχολυτ

0