我在stringgrid中每一行加入了一个按钮,点击按钮后show出另一个窗体,然后双击这个stringgrid中的一行值后赋给另一个主stringgrid?在那一行的按扭上点的就赋给那一行?
解决方案 »
- 关于继承窗口中的DBGrid删除列的问题
- D7求一段自动配置BDE的代码,救命!
- fastreport问题:如何在程序中直接打开带密码的fr报表。
- 请问 dbgrideh 控件的 STFilter 如何使用 ????????????? 急!!!!!!!
- 请问trunc是什么函数
- 关于dbgrid中的日期格式问题
- 公司要我开发一套基于 GPRS 技术的远程抄表系统的演示软件,我现在无从下手
- 如何将多个stringlist里的值写入文本文件??
- 公司没有给我们规划职业成长道路,自己如何规划好自己的未来之路?欢迎讨论!
- 低手问题,很急,请看
- 如何把两个日期相减得到天数
- 工资计算问题(access数据库)
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, Menus, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure ButtonClick(Sender: TObject);
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}var
vButtons: array of TButton;procedure TForm1.ButtonClick(Sender: TObject);
begin
if Form2.ShowModal <> mrOK then Exit;
StringGrid1.Rows[StringGrid1.Row] :=
Form2.StringGrid1.Rows[Form2.StringGrid1.Row];
end;procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
vRect: TRect;
begin
SetLength(vButtons, StringGrid1.VisibleRowCount);
for I := Low(vButtons) to High(vButtons) do
begin
vRect := StringGrid1.CellRect(StringGrid1.ColCount - 1, I);
vButtons[I] := TButton.Create(StringGrid1);
vButtons[I].Parent := StringGrid1.Parent;
OffsetRect(vRect, StringGrid1.Left + 2, StringGrid1.Top + 27);
vButtons[I].BoundsRect := vRect;
vButtons[I].Tag := I;
vButtons[I].OnClick := ButtonClick;
end;
end;end./////////////////----------------------------unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;type
TForm2 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.StringGrid1DblClick(Sender: TObject);
begin
ModalResult := mrOK;
end;procedure TForm2.FormCreate(Sender: TObject);
var
I, J: Integer;
begin
for I := 0 to StringGrid1.ColCount - 1 do
for J := 0 to StringGrid1.RowCount - 1 do
StringGrid1.Cells[I, J] := Format('%d,%d', [I, J]);
end;end.
begin
StringGrid1.Row := StringGrid1.TopRow + TButton(Sender).Tag; //如果行数多加上这一条
if Form2.ShowModal <> mrOK then Exit;
StringGrid1.Rows[StringGrid1.Row] :=
Form2.StringGrid1.Rows[Form2.StringGrid1.Row];
end;procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
vRect: TRect;
begin
StringGrid1.RowCount := 15;
SetLength(vButtons, StringGrid1.Height div StringGrid1.DefaultRowHeight - 1); //这里修改
for I := Low(vButtons) to High(vButtons) do
begin
vRect := StringGrid1.CellRect(StringGrid1.ColCount - 1, I);
vButtons[I] := TButton.Create(StringGrid1);
vButtons[I].Parent := StringGrid1.Parent;
OffsetRect(vRect, StringGrid1.Left + 2, StringGrid1.Top + 27);
vButtons[I].BoundsRect := vRect;
vButtons[I].Tag := I;
vButtons[I].OnClick := ButtonClick;
end;
end;