用stringgrid,我想前面4列不能做修改,后面列可以修改
所以就在onselectsell事件中写
if stringgrid.col<4 then
stringgrid.options:=stringgrid.options-[onediting]
else
stringgrid.options:=stringgrid.options+[onediting];就是想直接判断当前在哪列里,然后修改‘可编辑’的属性
但在onselectsell事件中太慢了
是点了后才判断前面这个要写在哪个事件里比较好,正好可以点下去就可以判断了 ???
所以就在onselectsell事件中写
if stringgrid.col<4 then
stringgrid.options:=stringgrid.options-[onediting]
else
stringgrid.options:=stringgrid.options+[onediting];就是想直接判断当前在哪列里,然后修改‘可编辑’的属性
但在onselectsell事件中太慢了
是点了后才判断前面这个要写在哪个事件里比较好,正好可以点下去就可以判断了 ???
解决方案 »
- TImage绘图的问题
- 请教高手:DBGridEh的分行显示问题--高分相送
- 大虾,救命啊。现有一MODEM,怎么样用Apro4.0控件写一个简单的传真发送程序?
- 为何我的线程总是自动终止?
- 求使用RichEdit 或 RxRichedit显示聊天记录的demo ,100分送上
- 急!!!!哪位大侠知道DELPHI 5的下载地址(企业版),十万火急,先送100分!!!!!!
- 已知窗口句柄,如何取得窗口的图标(ICON)的句柄?(还附加一问)
- 怎么样退出FORM?
- 大家来讨论一下车牌识别的技术吧
- 大家好
- 在DELPH的DBgrid表格中显示SQL SERVER用binary存储的日期
- 急!说我第2行‘=’附近有语法错误!
严格一点,通过鼠标右键跳出菜单里的复制、粘贴也要禁止
unit MyGrid;interfaceuses
Classes, Controls, Grids;type
TMyGrid = class(TStringGrid)
private
function CalcCoordFromPoint(X, Y: Integer;
const DrawInfo: TGridDrawInfo): TGridCoord;
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
public
end;implementation{ TMyGrid }procedure TMyGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
var
CellHit: TGridCoord;
DrawInfo: TGridDrawInfo;
MoveDrawn: Boolean;
begin
CalcDrawInfo(DrawInfo);
CellHit := CalcCoordFromPoint(X, Y, DrawInfo);
if CellHit.X < 4 then
Options := Options - [goEditing]; inherited; if (Button = mbLeft) and (CellHit.X >= 4) then
begin
Options := Options + [goEditing];
ShowEditor;
end;
end;function TMyGrid.CalcCoordFromPoint(X, Y: Integer;
const DrawInfo: TGridDrawInfo): TGridCoord; function DoCalc(const AxisInfo: TGridAxisDrawInfo; N: Integer): Integer;
var
I, Start, Stop: Longint;
Line: Integer;
begin
with AxisInfo do
begin
if N < FixedBoundary then
begin
Start := 0;
Stop := FixedCellCount - 1;
Line := 0;
end
else
begin
Start := FirstGridCell;
Stop := GridCellCount - 1;
Line := FixedBoundary;
end;
Result := -1;
for I := Start to Stop do
begin
Inc(Line, AxisInfo.GetExtent(I) + EffectiveLineWidth);
if N < Line then
begin
Result := I;
Exit;
end;
end;
end;
end; function DoCalcRightToLeft(const AxisInfo: TGridAxisDrawInfo; N: Integer): Integer;
var
I, Start, Stop: Longint;
Line: Integer;
begin
N := ClientWidth - N;
with AxisInfo do
begin
if N < FixedBoundary then
begin
Start := 0;
Stop := FixedCellCount - 1;
Line := ClientWidth;
end
else
begin
Start := FirstGridCell;
Stop := GridCellCount - 1;
Line := FixedBoundary;
end;
Result := -1;
for I := Start to Stop do
begin
Inc(Line, AxisInfo.GetExtent(I) + EffectiveLineWidth);
if N < Line then
begin
Result := I;
Exit;
end;
end;
end;
end;begin
if not UseRightToLeftAlignment then
Result.X := DoCalc(DrawInfo.Horz, X)
else
Result.X := DoCalcRightToLeft(DrawInfo.Horz, X);
Result.Y := DoCalc(DrawInfo.Vert, Y);
end;end.
然后动态建立一个Grid:
procedure TForm1.FormCreate(Sender: TObject);
begin
FGrid := TMyGrid.Create(Self);
FGrid.Parent := Self;
FGrid.ColCount := 10;
FGrid.Width := 400;
FGrid.Height := 200;
end;
key:=#0;
在onkeydown里就可以实现了
如果写在onkeypress里,很奇怪,如果我点可编辑的列(第4或第5列),然后再点不能编辑的列(0-3列),
点的那个列就可以输入了,不知道怎么回事重写有点麻烦,就没重写了