Remove items from combobox

 

Hello!

Is it possible to remove items from a Combobox?
I know that CComboBox.AddItem() can be used to add items to Combobox but I cannot figure out how to remove items from Combobox.


Thanks for taking your time.

 
nak4:Is it possible to remove items from a Combobox? I know that CComboBox.AddItem() can be used to add items to Combobox but I cannot figure out how to remove items from Combobox.

CComboBox has the following virtual methods. So use the ItemDelete one.

   virtual bool      ItemAdd(const string item,const long value=0)                    { return(m_list.ItemAdd(item,value));          }
   virtual bool      ItemInsert(const int index,const string item,const long value=0) { return(m_list.ItemInsert(index,item,value)); }
   virtual bool      ItemUpdate(const int index,const string item,const long value=0) { return(m_list.ItemUpdate(index,item,value)); }
   virtual bool      ItemDelete(const int index)                                      { return(m_list.ItemDelete(index));            }
   virtual bool      ItemsClear(void)                                                 { return(m_list.ItemsClear());                 }

When in doubt, look at the source code for the Standard Library ... "MQL5\Include\Controls\ComboBox.mqh"

 
Fernando Carreiro #:

CComboBox has the following virtual methods. So use the ItemDelete one.

When in doubt, look at the source code for the Standard Library ... "MQL5\Include\Controls\ComboBox.mqh"

I couldn't find those virtual methods.

It worked as I expected.
Thank you so much.

 
nak4 #:I couldn't find those virtual methods.It worked as I expected. Thank you so much.
You are welcome! Virtual methods are not described in the documentation unfortunately. You can only find out about them by looking at the source code. That is why I stated "When in doubt, look at the source code".
 
Fernando Carreiro #:
You are welcome! Virtual methods are not described in the documentation unfortunately. You can only find out about them by looking at the source code. That is why I stated "When in doubt, look at the source code".

I have another related question.  How to remove the current selected item in the combobox?

ItemDelete takes in index, but how to get index of current selected item?

Seems like the only way is to check the index via m_list, but this is protected variable.

I have to work around via the following codes:

class myCComboBox:public CComboBox
{
public:
   void CurrentItemDelete()
   {
      ItemDelete(m_list.Current());
   }
};

Am I missing something?