错了,重来: procedure TSTRINGGRID.DrawCell(...); begin if Assigned(FOnDrawCell) then FOnDrawCell(Self); end;const DrawCell = WM_USER + 1;procedure STRINGGRID(var Msg: TMessage); message STRINGGRID; ...procedure TSTRINGGRID.DrawCell(var Msg: TMessage); begin DrawCell; end;
在selectcell事件里判断 并用stringgrid1.Selection.属性固定位置。
在SelectCell事件里写. 这样 if acol=1 then begin Button1.Left :=stringgrid1.left+stringgrid1.CellRect(ACol,arow).Left; Button1.Top :=stringgrid1.Top+stringgrid1.CellRect(ACol,arow).top; button1.Visible :=true; end else button1.Visible :=false;
ARow: Integer; Rect: TRect; State: TGridDrawState);if (gdFocused in State) and (Trim(StringGrid1.Cells[acol,0])='抄表标志') then
begin
LI_I:=ACol; LI_J:=ARow;
combobox1.Text:=stringgrid1.Cells[ACol,ARow];
combobox1.Top:=Rect.Top+StringGrid1.top+3;
combobox1.Left:=Rect.Left+StringGrid1.Left+3;
combobox1.Height:=Rect.Bottom-Rect.Top;
combobox1.Width:=Rect.Right-Rect.Left;
combobox1.Visible:=true;
combobox1.Text:='';
LB_CBBZ:=false;
combobox1.Update;
combobox1.SetFocus;
end;当然,用鼠标点击目标列,可以看到combobox控件,
但是不用鼠标点击,就用鍵盘上的光标键来选择小格子,当用向左光标键从右向左
调动时,调动到目标列时,就看不到这个combobox控件!所以我才提出如何调用StringGrid控件的DrawCell事件!
分不够的话,可以再加 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
begin
//here your code is ok;
end;
DrawCell = WM_USER + 1;procedure STRINGGRID(var Msg: TMessage); message FHLM_STRINGGRID;
...procedure STRINGGRID.DrawCell(var Msg: TMessage);
begin
DrawCell;
end;
procedure TSTRINGGRID.DrawCell(...);
begin
if Assigned(FOnDrawCell) then FOnDrawCell(Self);
end;const
DrawCell = WM_USER + 1;procedure STRINGGRID(var Msg: TMessage); message STRINGGRID;
...procedure TSTRINGGRID.DrawCell(var Msg: TMessage);
begin
DrawCell;
end;
并用stringgrid1.Selection.属性固定位置。
这样
if acol=1 then
begin Button1.Left :=stringgrid1.left+stringgrid1.CellRect(ACol,arow).Left;
Button1.Top :=stringgrid1.Top+stringgrid1.CellRect(ACol,arow).top;
button1.Visible :=true;
end else
button1.Visible :=false;