如何实现按住Ctrl键,用鼠标点击记录实现的多选?
解决方案 »
- 一段delphi代码,不懂什么意思求解释
- 关于进度条的问题,请大家进来看看!
- 关于公章效果中文字旋转文字角度计算原理?
- 可以给我一个解决方案吗?我需要:一次性(!)实时(!)录入五万条记录,有一定的速度保证,本地数据库,(次次要条件)以后也有可能扩展到网络数据
- com组件使用时出错,很急,在线等待,100分!
- 急需vclzip for bcb6的注册版,谁有发给我,兄弟感激不尽,100分送上!
- 视频连接的问题
- 万分紧急!!idftp的问题!
- dbgrid问题
- 100分求控件:主窗口分两列(类似于IE),左边窗口的右边框上有一个箭头,点一下窗口隐藏到左边框,同时边框上显示向右的箭头,再点一下
- 请问,Edit控制可以设置一个数组序列吗?
- 求解:delphi中我在存储过程控件选择存储过程名时,为什么总是这样的:dbo.存储过程名;1
加上
goRowSelect
TCustomGrid = class(TCustomControl)
//....
property Selection: TGridRect read GetSelection write SetSelection;
//....
end;从这个定义来看,选择区域只能是一个矩形~~
如果想实现就需要自己加上选中的标志,然后在绘制Cell的地方处理标志~~
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Buttons;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
private
{ Private declarations }
FFlags: TList;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
I: Integer;
begin
if Button <> mbLeft then Exit;
TStringGrid(Sender).MouseToCell(X, Y, X, Y);
if Y < TStringGrid(Sender).FixedRows then Exit;
if ssCtrl in Shift then
I := FFlags.IndexOf(Pointer(Y))
else begin
FFlags.Clear;
I := -1;
end;
if I < 0 then
FFlags.Add(Pointer(Y))
else FFlags.Delete(I);
TStringGrid(Sender).Repaint;
end;procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
FFlags := TList.Create;
FFlags.Add(Pointer(1));
for I := 1 to StringGrid1.RowCount - 1 do
StringGrid1.Cells[1, I] := IntToStr(I);
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
FFlags.Free;
end;type
TStringGridEx = class(TStringGrid)
end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
if ACol < TStringGridEx(Sender).FixedCols then Exit;
if FFlags.IndexOf(Pointer(ARow)) < 0 then Exit;
TStringGridEx(Sender).OnDrawCell := nil;
try
TStringGrid(Sender).Canvas.Font.Color := clRed;
TStringGrid(Sender).Canvas.Brush.Color := clHighlight;
TStringGridEx(Sender).DrawCell(ACol, ARow, Rect, State);
finally
TStringGridEx(Sender).OnDrawCell := StringGrid1DrawCell;
end;
end;end.