ComboBox and reverse order?

Hello,

I was wondering if it was possible to have the entries in a combo box being ordered
in reverse order. Specifically, I would like to have something like the ‘command’ widget
in TGEditor,

fSix = new TGComboBox(f3V,"");
fSix->Resize(100,25);
fSixCommand = fSix->GetTextEntry();
fSixCommandBuffer = fSixCommand->GetBuffer();
fSixCommand->Associate(fSix);

but with the entries sorted with the last ‘command’ appearing first in the list.

Thanks in advance,

Bertrand Roessli

Hi Bertrand,

Why don’t you add the entries (command) directly in the order you want (using TGComboBox::InsertEntry())?
Otherwise I’m afraid that you have to make the sort yourself…
If you don’t know how to do it, or if I misunderstood the problem, feel free to post a running macro showing what you want to achieve, and I’ll take a look.

Cheers, Bertrand.

Hello,

I did it that way and it works for me

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGWindow.h>

class MyMainFrame : public TGMainFrame {

private:
   TGCompositeFrame    *fHor1;
   TGTextButton        *fExit;
   TGComboBox          *fSix;
   TGTextEntry         *fSixCommand;
   TGTextBuffer        *fSixCommandBuffer;     
   std::vector<std::string>  entries;

public:
   MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyMainFrame();
   void DoSetlabel();
   
   ClassDef(MyMainFrame, 0)
};
                          
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
   : TGComboBox(), TGMainFrame(p, w, h)
{

   fHor1 = new TGHorizontalFrame(this, 60, 20);
   fExit = new TGTextButton(fHor1, "&Exit", "gApplication->Terminate(0)");
   
   fSix = new TGComboBox(fHor1,"");
   fSix->Resize(100,25);
   fSix->Connect("ReturnPressed()","MyMainFrame", this,"DoSetLabel()");   

   fHor1->AddFrame(fExit);
   fHor1->AddFrame(fSix);

   AddFrame(fHor1);

   SetCleanup(kDeepCleanup);
   SetWindowName("ComboBox");
   MapSubwindows();
   Resize(GetDefaultSize());
   MapWindow();
}

MyMainFrame::DoSetLabel()
{
  TGTextEntry *te;
  te = fSix->GetTextEntry();
  const char* text = te->GetText();
  std::string tmp(text);
  entries.push_back(tmp);
  fSix->RemoveAll();
  for (int i = entries.size(); i > 0; --i)
  {
    fSix->AddEntry(entries[i-1].c_str(),i);
  }
}

MyMainFrame::~MyMainFrame()
{
   // Destructor.
   
   Cleanup();
}

void ComboBox()
{
   new MyMainFrame(gClient->GetRoot(), 50, 50); 
}

Thanks,

Bertrand Roessli