콤보박스에서 대분류를 선택하면 추출이 되어서 다른 콤보박스에 내용이 들어가게 했는데 딱 한번만 되니 이게 어떻게 된건지 모르겠네여..
한번은 제대로 들어가는데 다시 대분류에서 다른 아이템을 선택하면 그내용 그대로이니 부탁드립니다.
다음은 쏘스입니다.
//시작할때 대분류에 아이템을 뿌려줍니다.
procedure TTradeF.FormCreate(Sender: TObject);
begin
DateTimePicker1.Date := date;
with qryLarge do begin
close;
sql.Clear;
sql.Add('select LargeName');
sql.Add('from LargeCode');
open;
while not EOF do begin
cblarge.Items.add(FieldByName('largeName').AsString);
next;
end;
end;
end;
//대분류 콤보박스의 아이템을 바꿀때마다 중분류 아이템이 바뀝니다.
procedure TTradeF.cblargeChange(Sender: TObject);
begin
if cblarge.itemindex > 0 then
with qryMiddle do begin
Case cblarge.ItemIndex of
0 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''A%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
1: begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''B%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
2 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''C%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
3 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''D%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
4 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''E%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
5 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''F%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
6 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''G%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
7 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''H%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
8 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''I%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
9 : begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''J%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
10: begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''K%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
11: begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''L%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
12: begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''M%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
13: begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''N%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
14: begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''O%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
15: begin
Close;
sql.Clear;
sql.add('select MiddleName');
sql.add('from middlecode');
sql.add('where 중코드 like ''P%''');
open;
While not EOF do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
next;
end; //while
end;//begin
end;//case
Close;
Open;
end; //with의 끝
END;
혹시 추가 되어 들어간거 아닌가염..?
그리고 제 나름대로 좀 고쳐 봤어염.. (지송)
procedure TTradeF.FormCreate(Sender: TObject);
begin
DateTimePicker1.Date := date;
with qryLarge do begin
close;
sql.Clear;
sql.Add('select distinct LargeName');
sql.Add('from LargeCode');
open;
cblarge.Items.clear;
while not EOF do begin
cblarge.Items.add(FieldByName('largeName').AsString);
next;
end;
end;
end;
//대분류 콤보박스의 아이템을 바꿀때마다 중분류 아이템이 바뀝니다.
procedure TTradeF.cblargeChange(Sender: TObject);
var select_result : string;
begin
Case cblarge.ItemIndex of
0: select_result := 'A%';
1: select_result := 'B%';
2: select_result := 'C%';
3: select_result := 'D%';
4: select_result := 'E%';
5: select_result := 'F%';
6: select_result := 'G%';
7: select_result := 'H%';
8: select_result := 'I%';
9: select_result := 'J%';
10: select_result := 'K%';
12: select_result := 'L%';
13: select_result := 'M%';
14: select_result := 'N%';
15: select_result := 'O%';
end else begin
MessageDlg('검색할 조건이 아닌데염..?',
MtWarning, [mbok], 0);
exit;
end;
with qryMiddle do begin
close;
sql.clear;
sql.add('select MiddleName from middlecode where 중코드 like :중코드');
parambyname('중코드').value := select_result;
open;
cbmiddle.Items.clear;
while not qrymiddle.eof do begin
cbmiddle.Items.add(FieldByName('middleName').AsString);
qrmiddle.next;
end;
close;
end;
end;