Load items in a combobox from the select of another combobox

1

I have a Combobox that lists school units coming from my DB. Here is the code:

_fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)   {
QueryUnidade->Close();
QueryUnidade->Open();

while (QueryUnidade->Eof == false){
   ComboBoxUn->Items->Add(QueryUnidade->FieldByName("unidade")->AsString);
   QueryUnidade->Next();
}

}

In my other combobox I need to list the shifts that are associated with the drive chosen in the first combobox, but it is not appearing. My code looks like this:

void __fastcall TForm1::ComboBoxTurnoChange(TObject *Sender)    {

QueryTurno->Close();
QueryTurno->ClearFields();
QueryTurno->SQL->Add("SELECT DISTINCT TURNO FROM ALUNO WHERE UNIDADE ='"+  (Trim(ComboBoxUn->Text)+"'"));
QueryTurno->Open();

while(QueryTurno->Eof == false){
    ComboBoxTurno->Items->Add(QueryTurno->FieldByName("turno")->AsString);
   QueryTurno->Next();
}
 ComboBoxTurno->Update();
}
    
asked by anonymous 03.12.2015 / 14:13

1 answer

0

The program did not work because it was OK to do the procedure shown in OnSelect of the first combobox (ComboboxUn). The code looks like this:

void __fastcall TForm1::ComboBoxUnSelect(TObject *Sender)
{
    QueryTurno->Close();
    QueryTurno->SQL->Add("SELECT DISTINCT TURNO FROM ALUNO WHERE UNIDADE="+QuotedStr(Trim(ComboBoxUn->Text)));
    QueryTurno->Open();

    while(QueryTurno->Eof == false){
       ComboBoxTurno->Items->Add(QueryTurno->FieldByName("turno")->AsString);
       QueryTurno->Next();
    }
}

This way when an option is selected in the first combobox automatically the other options are listed in the second.

    
04.12.2015 / 17:39