Q&A

  • 2개이상의 combobox 동적 선택에 대한 질문입니다.
저번에도 질문했던 초보입니다.

combobox가 2개 이상일때요..

즉, 분류가 대,중,소분류일때 대분류에서 선택하면 중분류는 대분류에 해당하는 값만나오구.. 중분류선택하면 소분류도 중분류에 해당하는 값만 나오게끔 할려고 하는데요..



procedure TForm1.FormShow(Sender: TObject);

var seldir : string;

begin

with Query1 do begin

Close;

SQL.Clear;

SQL.Add('SELECT distinct dir FROM bunrutable');

Open;

first;

while Not EOF do

begin

ComboBox1.items.add(fieldbyname('dir').asstring);

Next;

end;



end;

Application.ProcessMessages;

end;



procedure TForm1.ComboBox1Change(Sender: TObject);

var seldir : string;

begin

with Query1 do begin

try

close;

sql.Clear;

SQL.add('select distinct sub from bunrutable');

SQL.add(' where dir = :Pdir');

parambyname('Pdir').asstring := combobox1.items[combobox1.itemindex];

open;

first;

while Not Eof do

begin

ComboBox2.items.add(fieldbyname('sub').asstring);

Next;

end;

combobox2.itemindex := 0; // 코드 콤보를 첫번째 값으로...

except

showmessage('코드정보 읽기에러');

end;



end;

end;



이렇게 하면 combobox1.items[combobox1.itemindex]의 값이 처음 combbobox1에서 선택한 값을 계속 물고 있네요..

일단 2개의 combobox선택이 되면 3개이상도 될 수 있을것 같은데.. 고수님들 부탁합니다.





2  COMMENTS
  • Profile
    까마귀 2000.12.15 22:19
    김종곤 wrote:

    > 저번에도 질문했던 초보입니다.

    > combobox가 2개 이상일때요..

    > 즉, 분류가 대,중,소분류일때 대분류에서 선택하면 중분류는 대분류에 해당하는 값만나오구.. 중분류선택하면 소분류도 중분류에 해당하는 값만 나오게끔 할려고 하는데요..

    >

    > procedure TForm1.FormShow(Sender: TObject);

    > var seldir : string;

    > begin

    > with Query1 do begin

    > Close;

    > SQL.Clear;

    > SQL.Add('SELECT distinct dir FROM bunrutable');

    > Open;

    > first;

    > while Not EOF do

    > begin

    > ComboBox1.items.add(fieldbyname('dir').asstring);

    > Next;

    > end;

    >

    > end;

    > Application.ProcessMessages;

    > end;

    >

    > procedure TForm1.ComboBox1Change(Sender: TObject);

    > var seldir : string;

    > begin

    > with Query1 do begin

    > try

    > close;

    > sql.Clear;

    > SQL.add('select distinct sub from bunrutable');

    > SQL.add(' where dir = :Pdir');

    > parambyname('Pdir').asstring := combobox1.items[combobox1.itemindex];

    > open;

    > first;

    > while Not Eof do

    > begin

    > ComboBox2.items.add(fieldbyname('sub').asstring);

    > Next;

    > end;

    > combobox2.itemindex := 0; // 코드 콤보를 첫번째 값으로...

    > except

    > showmessage('코드정보 읽기에러');

    > end;

    >

    > end;

    > end;

    >

    > 이렇게 하면 combobox1.items[combobox1.itemindex]의 값이 처음 combbobox1에서 선택한 값을 계속 물고 있네요..

    > 일단 2개의 combobox선택이 되면 3개이상도 될 수 있을것 같은데.. 고수님들 부탁합니다.

    >

    >



    안녕하세요. 까마귀입니다.



    일단 combobox1.items[combobox1.itemindex] 이부분은 이렇게 선택하는게 맞고요.

    ComboBox1의 Item을 선택을 하면 ComboBox2의 Item의 내용이 변해야 하는것 같군요.

    그런데, 이부분이 잘못된것 같군요.



    while Not Eof do

    begin

    ComboBox2.items.add(fieldbyname('sub').asstring);

    Next;

    end;



    ComboBox1의 Item을 선택하면 그에 맞는 내용을 ComboBox2에 추가하는건데,

    추가만 하고, 삭제는 하지 않으니 계속 Item만 늘어나게 되네요.

    이렇게 한 문장을 추가해야 합니다.



    ComboBox2.Items.Clear; <-- 이 문장.

    while Not Eof do

    begin

    ComboBox2.items.add(fieldbyname('sub').asstring);

    Next;

    end;



    그러면, ComboBox1이 변했을 경우, 먼저 ComboBox2의 Item을 지우고, 추가를 합니다.

    이렇게 하면 제대로 되겠군요.







    위대한 단군혼이 살아있는 나라.... 대한민국.

  • Profile
    최은석 2000.12.15 21:20
    아래부분을 수정하세요

    parambyname('Pdir').asstring := combobox1.items[combobox1.itemindex];



    다음처럼요....

    parambyname('Pdir').asstring := combobox1.text;











    김종곤 wrote:

    > 저번에도 질문했던 초보입니다.

    > combobox가 2개 이상일때요..

    > 즉, 분류가 대,중,소분류일때 대분류에서 선택하면 중분류는 대분류에 해당하는 값만나오구.. 중분류선택하면 소분류도 중분류에 해당하는 값만 나오게끔 할려고 하는데요..

    >

    > procedure TForm1.FormShow(Sender: TObject);

    > var seldir : string;

    > begin

    > with Query1 do begin

    > Close;

    > SQL.Clear;

    > SQL.Add('SELECT distinct dir FROM bunrutable');

    > Open;

    > first;

    > while Not EOF do

    > begin

    > ComboBox1.items.add(fieldbyname('dir').asstring);

    > Next;

    > end;

    >

    > end;

    > Application.ProcessMessages;

    > end;

    >

    > procedure TForm1.ComboBox1Change(Sender: TObject);

    > var seldir : string;

    > begin

    > with Query1 do begin

    > try

    > close;

    > sql.Clear;

    > SQL.add('select distinct sub from bunrutable');

    > SQL.add(' where dir = :Pdir');

    > parambyname('Pdir').asstring := combobox1.items[combobox1.itemindex];

    > open;

    > first;

    > while Not Eof do

    > begin

    > ComboBox2.items.add(fieldbyname('sub').asstring);

    > Next;

    > end;

    > combobox2.itemindex := 0; // 코드 콤보를 첫번째 값으로...

    > except

    > showmessage('코드정보 읽기에러');

    > end;

    >

    > end;

    > end;

    >

    > 이렇게 하면 combobox1.items[combobox1.itemindex]의 값이 처음 combbobox1에서 선택한 값을 계속 물고 있네요..

    > 일단 2개의 combobox선택이 되면 3개이상도 될 수 있을것 같은데.. 고수님들 부탁합니다.

    >

    >