你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:技术专栏 / Linux开发
怎样获得DBGrid中的cell的坐标???
 

//新建一个工程,在窗体上加一个StringGrid

//下面是unit1.pas

unit Unit1;

interface

uses
  Windows  Messages  SysUtils  Classes  Graphics  Controls  Forms  Dia

logs
  Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DblClick(Sender: TObject);
    procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X  Y: Integer);
    procedure StringGrid1Click(Sender: TObject);

  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

const
  WeekDayName :Array[1..7] of String=('星期一' '星期二' '星期三' '星期四
' '星期五' '星期六' '星期日');

var
  X_Pos Y_Pos:integer;//鼠标在窗体的位置
  Col_Pos Row_Pos:integer;//单元位置

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  i:integer;
begin
  Application.HintPause:=100;
  Font.Size :=10;
  Caption:='STring岩石程序';
  StringGrid1.ShowHint :=True;
  StringGrid1.ColCount :=8;
  StringGrid1.RowCount :=12;
  StringGrid1.Cells[0 0]:='第18周';
  for i:=1 to StringGrid1.ColCount -1  do
  StringGrid1.Cells[i 0]:=WeekDayName[i];
  for i:=1 to StringGrid1.RowCount -1 do
    StringGrid1.Cells[0 i]:=InttoStr(i+7)+':00';
  StringGrid1.Options :=StringGrid1.Options+[goTabs goROwSizing goColSizing]-[goEditing];
end;

procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
  SchemeItem:String;
begin
  StringGrid1.MouseToCell(X_Pos Y_Pos Col_Pos Row_Pos) ;  //转换到单位位置
  if (Col_Pos<0 )or (Row_Pos<0 ) then
    Exit;
  if (StringGrid1.Cells[Col_Pos Row_Pos]<>''  ) then //取消计划概要
  begin
    StringGrid1.Cells[Col_Pos Row_Pos]:='';
    Exit;
  end;
  SchemeItem:=InputBox('提示' '请输入计划概要:' '会议');
  StringGrid1.Cells[Col_Pos Row_Pos]:=SchemeItem;
End;

procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X  Y: Integer);
begin
  X_Pos:=x;
  Y_Pos:=y;
end;

procedure TForm1.StringGrid1Click(Sender: TObject);
begin
  StringGrid1.MouseToCell(X_Pos Y_Pos Col_Pos Row_Pos);//转化到单元位置
  StringGrid1.Hint :=StringGrid1.Cells[Col_Pos Row_Pos];//暂时借用该特性显示工作计划
end;

end.

(编辑:aniston)

  推荐精品文章

·2024年12月目录 
·2024年11月目录 
·2024年10月目录 
·2024年9月目录 
·2024年8月目录 
·2024年7月目录 
·2024年6月目录 
·2024年5月目录 
·2024年4月目录 
·2024年3月目录 
·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089