继承CustomGrid做了一个表格控件,遇见一个问题,请高手入内帮忙看看!(200分)

S

sundart

Unregistered / Unconfirmed
GUEST, unregistred user!
我在其中加入了一个控件,用来编辑和显示特定的字段类型。

现在显示完全正常,但是不能编辑,一编辑表格的Cell就会覆盖我的控件,
恢复他本来的面目。我的控件不能取得焦点,
如果执行SetFocus,会出现:‘Control’ has no Parent window;
 
你是如何实现的?
 
也就是我在表格中嵌入了个控件用来显示和编辑数据。
现在显示完全正常,但是不能编辑,一编辑表格的Cell就会覆盖我的控件,
恢复他本来的面目。我的控件不能取得焦点,
如果执行SetFocus,会出现:‘Control’ has no Parent window;
 
TTyDBGrid = class(TCustomGrid)
private
FCurrencyStyle: TTyCurrencyStyle;
...
constructor TCustomDBGridEh.Create(AOwner: TComponent);
begin
...
FCurrencyStyle := TTyCurrencyStyle.Create(Self);
end;
procedure TTyDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
begin
...
if DrawColumn.GetColumnType = ctCurrency then //判断是否特定类型
begin
FillRect(ARect);
FCurrencyStyle.Left := ARect.Left + Left + 2;
FCurrencyStyle.Top := ARect.Top + top + 2;
FCurrencyStyle.Width := ARect.Right - ARect.Left;
FCurrencyStyle.Height := ARect.Bottom - ARect.Top;
FCurrencyStyle.DrawCurrencyFrame(Canvas, ARect, DrawColumn);
end;
...
end;
现在显示是正确了,但如果我要编辑应该在什么地方写代码,
也就是说当Cell的State为gdFocused时,编辑应该在FCurrencyStyle中。

qq:37112072,在线等待中。。。
 
>>>Control’ has no Parent window

那是说你还没有对FCurrencyStyle的parent赋值
》》constructor TCustomDBGridEh.Create(AOwner: TComponent);
>>begin
>> ...
FCurrencyStyle := TTyCurrencyStyle.Create(Self);
FCurrencyStyle.parent :=self; //加这句试试
>>end;
 
有错,
‘Cannot focus a disalbed or invisible window’
 
>>有错,
>> ‘Cannot focus a disalbed or invisible window’
你在FCurrencyStyle.setfocus时一定要先确保
FCurrencyStyle.Enabled:=TRUE
FCurrencyStyle.Visible:=TRUE;
 
这个错误已经解决,谢谢。

我将FCurrencyStyle指定了FieldName,如何让它的值自动随字段变化呢?
 
接受答案了.
 
顶部