Problem with СComboBox

 

Hi to all! I have a problem: several comboBoxes are created (the number is not fixed), the class object is created as an array

CComboBox combo[];          

Then I create the ComboBoxes themselves:

 void SubWindowCreate( int count, ulong event_id, string event_name)
{
   long id= ChartID ();
   string obj_name=prefix+ IntegerToString (event_id)+ " | " + IntegerToString (count);

   ArrayResize (combo,count+ 1 );
   
   int width=( int ) ChartGetInteger (id, CHART_WIDTH_IN_PIXELS );
   int height=( int ) ChartGetInteger (id, CHART_HEIGHT_IN_PIXELS );
   
   int w=width/ 2 - 200 +( 22 *count);
   int h=height/ 2 - 100 +( 22 *count);

   if (dialog2[count].Create(id,obj_name, 0 ,w,h,w+ 400 ,h+ 250 , false ))
   {
      dialog2[count].Caption(prefix+event_name);
      
      combo[count].ListViewItems( 8 );
       if (combo[count].Create(id,obj_name+ " | " + "combo" , 0 , 150 , 10 , 250 , 30 ))
      {
         for ( int i= 0 ;i< SymbolsTotal ( true );i++)combo[count].ItemAdd( SymbolName (i, true ),i);
         combo[count].SelectByValue( 0 );
      }

      dialog2[count].Add(combo[count]);
      dialog2[count].Run();
      dialog2[count].Hide();
   }
}

But I get this strange behavior:

Can anyone help? Tell me what I did wrong?

 



Hi! It looks like you're dynamically creating combo boxes in a loop and adding them to dialogs, but you're encountering some issues. When resizing the combo array with ArrayResize(combo, count + 1);, make sure that count is incremented properly. Similarly, ensure that dialog2 is resized if it's an array.


 
Larry Martin # :



Hi! It looks like you're dynamically creating combo boxes in a loop and adding them to dialogs, but you're encountering some issues. When resizing the combo array with ArrayResize(combo, count + 1);, make sure that count is incremented properly. Similarly, ensure that dialog2 is resized if it's an array.


Hi Larry! Thank you for your reply. but, alas, this is not the case... I checked the correctness of the arrays, everything is ok. I suspect the problem here is:

 void OnChartEvent ( const int id,          
                   const long & lparam,
                   const double & dparam,
                   const string & sparam)
{
   dialog1.OnEvent(id,lparam,dparam,sparam);
   for ( int i= 0 ;i< ArraySize (dialog2);i++)
   {
       if (dialog2[i].IsVisible())dialog2[i].OnEvent(id,lparam,dparam,sparam);
   }
   
   if (id== CHARTEVENT_OBJECT_CLICK )
   {
       for ( int i= 0 ;i< ArraySize (button1);i++)
      {
         if (sparam==button1[i].Name())
         {
             if (button1[i].Pressed())
            {
               if (button1[i].ColorBackground()==PastColor)
               {
                   MessageBox ( "The event has already passed! Trade is impossible!" , "Trade is impossible" , MB_ICONWARNING );
                  button1[i].Pressed( false );
               }
               else 
               {
                  button1[i].ColorBackground(PressedColor);
                  ChangeLineColor(button1[i].Text(),PressedColor);
                   if (!dialog2[i].IsVisible())dialog2[i].Show();
               }
            }
             else HideDialog2(i);
         }
         else if (sparam==button2[i].Name())HideDialog2(i);
      }
   }
   ChartRedraw ();
}

But of course I'm not sure...

 

Just in case, here's the full code:

Files:
 
Maksim Neimerik #:

Just in case, here's the full code:

When you create the dialogs set different dialog IDs for each new dialog and make sure that the difference is more than the number of controls used in each. 

//dialog1.Id(0) this does not need to be set as that is the default
dialog2[0].Id(100) // if dialog1 has less than 100 controls
dialog2[1].Id(200) // if dialog2[0] has less than 100 controls
//etc..
 
Laszlo Tormasi #:

When you create the dialogs set different dialog IDs for each new dialog and make sure that the difference is more than the number of controls used in each. 

Thank you very much! I will try... I think it make sense...
 
Laszlo Tormasi # :

When you create the dialogs set different dialog IDs for each new dialog and make sure that the difference is more than the number of controls used in each. 

It works great! A huge THANK YOU! You have no idea how much time I spent figuring this out...

 
Hi to all! Please tell me how to specify the priority (ZOrder) for the СComboBox object?