안녕하십니까? 델파이로 열씸이 하는데 디비그리드 안에 디비콤보를 넣는데서 며칠째 진행이 안되고 있습니다.
구체적으로 그리드에서 한 컬럼에 입력된 값에 따라 다른 컬럼에서 콤보박스를 이용해 종류별로 lookup해주는 것을 해결할려고 하는데..
일단 해당그리드에 클릭하거나 keydown을 하면 DB콤보박스가 떠야 하는데 도대체 안되고 있습니다.
아래와 같이 1), 2) 도 각각 안되거니와 물론 처음부터 1), 2)없는 상태에서도 안되고 있습니다.
무엇이 문제인지.. 혹 다른 것을 설정해야 하는지..
답변 꼭 좀 부탁드립니다.
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer;
Column: TColumn; State: TGridDrawState);
begin if(gdFocused in State) then
begin
if DBGrid1.SelectedField.fieldName = 'BOOKITEM' then
// if (Column.FieldName = DBComboBox1.DataField ) then
// if DBGrid1.Column.FieldName = 'BOOKITEM' then
begin
Label1.visible := true;
DBComboBox1.Left := Rect.Left + DBGrid1.Left;
DBComboBox1.Top := Rect.Top + DBGrid1.Top;
DBComboBox1.Width := Rect.Right - Rect.Left;
// DBComboBox1.Height := Rect.Bottom - Rect.Top;
// DBComboBox1.visible := true;
// DBComboBox1.SetFocus;
end
else
Label1.visible := false;
DBComboBox1.visible := false;
end;
end;
1) procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin if key = vk_f4 then
if DBGrid1.SelectedField.FieldName = 'BOOKITEM' then
begin
DBComboBox1.visible := true;
DBComboBox1.SetFocus;
PostMessage(DBCombobox1.Handle, WM_KEYDOWN, VK_F4, 0);
end
end;
2) {procedure Tform1.DBCombobox1closeup(Sender: TObject);
Begin DBCombobox1.visible := true;
with Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select itemName from library where itemtype = :s1 ');
ParamByName('s1').AsString := Query1.FieldByName('ItemType').AsString;
end;
end;
}
김동섭 wrote:
소스를 포함한 답변을 드립니다요~ 디비콤보는 아니지만 콤보박스를
디비그리드에서 활용한 프로그램이에요.... 이렇게 쓰시는게 아주 좋을거 같군요...^^
아래 예제는 Del3로 개발한 금융기관에서 쓰는 프로그램의 소스일부입니다....
만약 더 필요하신것이 있으시면 소스를 팍팍 제공해드리지요....
procedure TForm1.DBG1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (gdFocused in State) then
if DBG1.SelectedField.fieldName = 'STAT' then
begin
CB_m_stat.Left := Rect.Left + DBG1.Left;
CB_m_stat.Top := Rect.Top + DBG1.Top;
CB_m_stat.Width := Rect.Right - Rect.left;
CB_m_stat.Height := Rect.Bottom - Rect.Top;
end
else if DBG1.SelectedField.fieldName = 'GJ_STAT' then
begin
CB_stat.Left := Rect.Left + DBG1.Left;
CB_stat.Top := Rect.Top + DBG1.Top;
CB_stat.Width := Rect.Right - Rect.left;
CB_stat.Height := Rect.Bottom - Rect.Top;
end
else if DBG1.SelectedField.fieldName = 'OWN' then
begin
CB_own.Left := Rect.Left + DBG1.Left;
CB_own.Top := Rect.Top + DBG1.Top;
CB_own.Width := Rect.Right - Rect.left;
CB_own.Height := Rect.Bottom - Rect.Top;
end
else if DBG1.SelectedField.fieldName = 'MGR' then
begin
CB_mgr.Left := Rect.Left + DBG1.Left;
CB_mgr.Top := Rect.Top + DBG1.Top;
CB_mgr.Width := Rect.Right - Rect.left;
CB_mgr.Height := Rect.Bottom - Rect.Top;
end
end;
procedure TForm1.DBG1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = vk_f4 then
if DBG1.SelectedField.FieldName = 'STAT' then
begin
CB_m_stat.Visible := True;
CB_m_stat.SetFocus;
PostMessage(CB_m_stat.Handle, WM_KEYDOWN, VK_F4, 0);
end
else if DBG1.SelectedField.fieldName = 'GJ_STAT' then
begin
CB_stat.Visible := True;
CB_stat.SetFocus;
PostMessage(CB_stat.Handle, WM_KEYDOWN, VK_F4, 0);
end
else if DBG1.SelectedField.fieldName = 'OWN' then
begin
CB_own.Visible := True;
CB_own.SetFocus;
PostMessage(CB_own.Handle, WM_KEYDOWN, VK_F4, 0);
end
else if DBG1.SelectedField.fieldName = 'MGR' then
begin
CB_mgr.Visible := True;
CB_mgr.SetFocus;
PostMessage(CB_mgr.Handle, WM_KEYDOWN, VK_F4, 0);
end;
end;
procedure TForm1.CB_m_statExit(Sender: TObject);
var
i : Smallint;
s, tmp_s : string;
begin
if CB_m_stat.Text <> '' then
begin
i := 0;
s := CB_m_stat.Text;
if s[1] = '[' then
tmp_s := Copy(s, 2, 4)
else tmp_s := Copy(s, 1, 4);
while i <= CB_m_stat.Items.Count - 1 do
begin
if tmp_s = Copy(CB_m_stat.Items[i], 2, 4) then
begin
CB_m_stat.Text := CB_m_stat.Items[i];
break;
end;
Inc(i);
end;
end;
if i = CB_m_stat.Items.Count then
begin
MessageDlg('찾고자 하는 데이터가 없습니다.',mtError,[mbOk],0);
CB_m_stat.Text := '';
CB_m_stat.SetFocus;
end;
end;
procedure TForm1.CB_m_statKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
begin
if DS1.state in [dsInactive, dsBrowse] then
DS1.Edit;
DBG1.SetFocus;
P64E00_Q1m_stat2.Value := Copy(CB_m_stat.Text, 2, 2);
P64E00_Q1m_stat3.Value := Copy(CB_m_stat.Text, 4, 2);
P64E00_Q1stat.Value := CB_m_stat.Text;
PostMessage(DBG1.Handle, WM_KEYDOWN, VK_RIGHT, 0);
CB_m_stat.Text := '';
CB_m_stat.Visible := False;
end;
end;
> 고수님들께...
> 디비그리드 안에 디비콤보를 넣을 수 없나여...
> 방법을 좀 갈켜 주세요...
아래 제가 제작한 소스가 보이는데요~
저는 DBComboBox말고 그냥 Combobox 사용한 것입니다.
첨에는 Transaction문제