Sorry for the basic question here:
I have a couple of TGComboBox in my GUI. When I select an entry in one of them, I’d like to have the other one update automatically with the same value. I thought TGComboBox::Select() would work… as far as I can tell, the value may have correctly been selected, but the ComboBox doesn’t display the change. It’s like it is missing a TGComboBox::Update() like TCanvas::Update() after changes are made to a TCanvas. How do I force the update? Thanks in advance,
Fred
–
Below the snippet of code I use:
void SDGUI::EyeSelect(Int_t id){
(…)
// attempting to update value of both comboboxes with same id
fdEyeSelect->Select(id,kTRUE);
hyEyeSelect->Select(id,kTRUE);
}
Here is a (quick and dirty) example:
#include "TGFrame.h"
#include "TROOT.h"
#include "TGComboBox.h"
#include "TGTextEntry.h"
#include "Riostream.h"
TGComboBox *cb2;
void select(Int_t id)
{
cb2->Select(id, kFALSE);
// update the combo box text entry
cb2->GetTextEntry()->SetText(cb2->GetSelectedEntry()->GetTitle());
TGListBox *lb2 = cb2->GetListBox();
// update the scroll bar position
((TGLBContainer *)lb2->GetContainer())->SetVsbPosition(lb2->GetSelected());
}
void test_combobox()
{
TGMainFrame* mf = new TGMainFrame(gClient->GetRoot(), 200, 100, kHorizontalFrame);
TGComboBox *cb = new TGComboBox(mf, "");
mf->AddFrame(cb, new TGLayoutHints(kLHintsNormal, 5, 0, 5, 0));
cb2 = new TGComboBox(mf, "");
mf->AddFrame(cb2, new TGLayoutHints(kLHintsNormal, 5, 0, 5, 0));
cb->Connect("Selected(Int_t)", 0, 0, "select(Int_t)");
for (int i=0;i<100;++i) {
cb->AddEntry(Form("Entry %d", i), i);
cb2->AddEntry(Form("Entry %d", i), i);
}
cb->Resize(90, 20);
cb2->Resize(90, 20);
cb->Select(32, kTRUE);
cb->GetTextEntry()->SetText(cb->GetSelectedEntry()->GetTitle());
TGListBox *lb = cb->GetListBox();
lb->Resize(lb->GetWidth(), 200);
((TGLBContainer *)lb->GetContainer())->SetVsbPosition(lb->GetSelected());
mf->MapSubwindows();
mf->Layout();
mf->SetWindowName("TGComboBox Test");
mf->SetIconName("TGComboBox Test");
mf->SetClassHints("TGComboBox Test", "TGComboBox Test");
mf->MapWindow();
}
Hello Bertrand. Works perfect. Would have never guessed how to do this. Thanks!