W
wk_knife
Unregistered / Unconfirmed
GUEST, unregistred user!
先放一个DBMemo1,初始化visible:=False;
procedure TYanxinForm.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect;
Field: TField;
State: TGridDrawState);
begin
if not DBMemo1.Focused then
DBMemo1.Visible :=False;
//加这么一句,左右移动,包括调整列宽时都没有问题了
if (gdFocused in State) or (gdSelected in State) then
if Field.Datatype = ftMemo then
begin
DBMemo1.DataField :=Field.FieldName;
DBMemo1.Left := Rect.Left + DBGrid1.Left;
DBMemo1.Top := Rect.Top + DBGrid1.top;
DBMemo1.Width :=Rect.Right - Rect.Left;
DBMemo1.Height :=DBMemo1.Width;
DBMemo1.Visible := True;
end;
end;
procedure TYanxinForm.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName = DBMemo1.DataField then
DBMemo1.Visible := false;
end;
procedure TYanxinForm.DBGrid1KeyPress(Sender: TObject;
var Key: Char);
begin
if (key <> chr(9)) then
begin
if (DBGrid1.SelectedField.FieldName = DBMemo1.DataField) then
begin
DBMemo1.SetFocus;
SendMessage(DBMemo1.Handle, WM_Char, word(Key), 0);
end
else
begin
if Key=Char(VK_RETURN) then
begin
SendMessage(DBGrid1.Handle,WM_KEYDOWN, VK_DOWN,0);
Key:=Char(0);
end;
end;
end;
end;
procedure TYanxinForm.DBGrid1DrawDataCell(Sender: TObject;
const Rect: TRect;
Field: TField;
State: TGridDrawState);
begin
if not DBMemo1.Focused then
DBMemo1.Visible :=False;
//加这么一句,左右移动,包括调整列宽时都没有问题了
if (gdFocused in State) or (gdSelected in State) then
if Field.Datatype = ftMemo then
begin
DBMemo1.DataField :=Field.FieldName;
DBMemo1.Left := Rect.Left + DBGrid1.Left;
DBMemo1.Top := Rect.Top + DBGrid1.top;
DBMemo1.Width :=Rect.Right - Rect.Left;
DBMemo1.Height :=DBMemo1.Width;
DBMemo1.Visible := True;
end;
end;
procedure TYanxinForm.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName = DBMemo1.DataField then
DBMemo1.Visible := false;
end;
procedure TYanxinForm.DBGrid1KeyPress(Sender: TObject;
var Key: Char);
begin
if (key <> chr(9)) then
begin
if (DBGrid1.SelectedField.FieldName = DBMemo1.DataField) then
begin
DBMemo1.SetFocus;
SendMessage(DBMemo1.Handle, WM_Char, word(Key), 0);
end
else
begin
if Key=Char(VK_RETURN) then
begin
SendMessage(DBGrid1.Handle,WM_KEYDOWN, VK_DOWN,0);
Key:=Char(0);
end;
end;
end;
end;