速达的效果如下:
dbgrid:如:
--------------------------------------------------
| 商品名称 | 进价 | 数量 |
--------------------------------------------------
| 下拉框 ▲| 2.5 | |
--------------------------------------------------在下拉框中可以直接输入商名代码,如0011就可出现其对应的“电视机1”,,也可以从下拉框中选数据“电视机”,出现的下拉框如下:
---------------------
| 商名代码 | 商品名称 |
--------------------
| 0011 | 电视机1 |
--------------------
| 0012 | 电视机2 |
--------------------
| 0013 | 电视机3 |
--------------------当双击下拉框第一行时,对应的“电视机1”就被选作为当前下拉框的内容。请问这种效果如何实现,请说出具体步骤。
dbgrid:如:
--------------------------------------------------
| 商品名称 | 进价 | 数量 |
--------------------------------------------------
| 下拉框 ▲| 2.5 | |
--------------------------------------------------在下拉框中可以直接输入商名代码,如0011就可出现其对应的“电视机1”,,也可以从下拉框中选数据“电视机”,出现的下拉框如下:
---------------------
| 商名代码 | 商品名称 |
--------------------
| 0011 | 电视机1 |
--------------------
| 0012 | 电视机2 |
--------------------
| 0013 | 电视机3 |
--------------------当双击下拉框第一行时,对应的“电视机1”就被选作为当前下拉框的内容。请问这种效果如何实现,请说出具体步骤。
或:将DBLookupCombo1,DBCheckBox1,DBComboBox1等设为Visible := False;
在下列事件中调整显示.procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (Field.FieldName = DBLookupCombo1.DataField) then
begin
DBLookupCombo1.Left := Rect.Left + DBGrid1.Left;
DBLookupCombo1.Top := Rect.Top + DBGrid1.top;
DBLookupCombo1.Width := Rect.Right - Rect.Left;
DBLookupCombo1.Height := Rect.Bottom - Rect.Top;
DBLookupCombo1.Visible := True;
end
else if (Field.FieldName = DBCheckBox1.DataField) then
begin
DBCheckBox1.Left := Rect.Left + DBGrid1.Left + 1;
DBCheckBox1.Top := Rect.Top + DBGrid1.top + 1;
DBCheckBox1.Width := Rect.Right - Rect.Left{ - 1};
DBCheckBox1.Height := Rect.Bottom - Rect.Top{ - 1};
DBCheckBox1.Visible := True;
end
else if (Field.FieldName = DBComboBox1.DataField) then
begin
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;
end;
end;
end;procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField then
DBLookupCombo1.Visible := false
else If DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField then
DBCheckBox1.Visible := false
else If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then
DBComboBox1.Visible := false;
end;
---------------------
| 商名代码 | 商品名称 |
--------------------
| 0011 | 电视机1 |
--------------------
| 0012 | 电视机2 |
--------------------
| 0013 | 电视机3 |
--------------------