请问各位大侠: 如何做到修改stringgridr的cell内容后,按enter键确认,按esc键恢复原值??还有: 如何能做到Cell的显示格式根据数据库字段类型而变,如:字符类型的字段靠左对齐,整型数类型字段靠右对齐,浮点数类型靠右对齐并显示小数位急呀,最好有源码分析。。小第在此先谢了。。
解决方案 »
- ▲▲▲▲▲▲Delphi也疯狂:用Delphi实现的仿APPEON的Web构架
- 大家有谁用过xlgrid?
- 我要写关于索引,排序的论文,高分求相关资料
- 怎么灵活使用dbgird,如:加checkbox来delete记录,用adoquery修改某字段
- 请教信封打印及预览,高分相送
- 完蛋了,快要丢掉饭碗了:一台机器用拨号上网一台服务器在公司的内部网上,它们都可以访问因特网,怎样用TCP/IP(或UDP)互相通讯?
- 高分求解:Multiple _step operation generated errors,check each Status
- 如何让Win2000支持GB2312_Charset字符集
- 亲爱的delphi程序员们:)!
- 关于TADOConnection 控件的使用
- 如何在Fastreport 中按条件汇总?
- 如何选择一个容器中的所有控件?
procedure TInputGrid.DrawCell(ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
iTextWidth,iTextLeft: Integer;
tmpAlignment: TAlignment;
begin
inherited;
if ARow<FixedRows then tmpAlignment:=taCenter
else begin
if ACol<Length(FColFormat) then
tmpAlignment := FColFormat[ACol].Alignment
else
tmpAlignment := taLeftJustify;
end; iTextWidth := Canvas.TextWidth(Cells[ACol,ARow]);
iTextLeft := 2;
case tmpAlignment of
taLeftJustify: iTextLeft := 2;
taRightJustify: iTextLeft := Rect.Right-Rect.Left-iTextWidth-2;
taCenter: iTextLeft := (Rect.Right-Rect.Left-iTextWidth) div 2;
end; Canvas.TextRect(Rect,Rect.Left+iTextLeft,Rect.Top+2,Cells[ACol,ARow]);
end;上面这个是继承Drawcell方法,如果对stringgrid的OnDrawcell事件编程需要做一些改动,
你自己改吧。
大侠有恢复stringGrid 的cell内容的代码吗??
放两个stringGrid,stringGrid1和stringGrid2
stringGrid2.visibl:=false;var
Form1: TForm1;
i,j:integer;
k:boolean;
str:string;
implementation{$R *.dfm}procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_RETURN then
begin
i:=stringgrid1.Col;
j:=stringgrid1.row;
str:=stringgrid2.Cells[i,j];
stringgrid2.Cells[i,j]:=stringgrid1.Cells[i,j];
k:=true;
end;
if (k=true) and (Key = VK_ESCAPE) then
begin
stringgrid1.Cells[i,j]:=str;
stringgrid2.Cells[i,j]:=str;
k:=false;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var i,j:integer;
begin
for i:=1 to stringgrid1.ColCount do
begin
for j:=1 to stringgrid1.RowCount do
begin
StringGrid1.Cells[i,j]:=inttostr(i)+inttostr(j);
StringGrid2.Cells[i,j]:=inttostr(i)+inttostr(j);
end;
end;
k:=false;
end;procedure TForm1.StringGrid1Click(Sender: TObject);
var i,j:integer;
begin
if k=false then
begin
for i:=1 to stringgrid1.ColCount do
begin
for j:=1 to stringgrid1.RowCount do
begin
StringGrid1.Cells[i,j]:=StringGrid2.Cells[i,j];
end;
end;
end;
end;end.