Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 在TAdvStringGrid中选择具有隐藏列的单元格_Delphi_Interface_Delphi 2007_Tms - Fatal编程技术网

Delphi 在TAdvStringGrid中选择具有隐藏列的单元格

Delphi 在TAdvStringGrid中选择具有隐藏列的单元格,delphi,interface,delphi-2007,tms,Delphi,Interface,Delphi 2007,Tms,我正在TAdvStringGrid中选择某个单元格: const MyCol=4; MyRow=1; HiddenCol=2; procedure TForm1.FormCreate(Sender: TObject); begin AdvStringGrid1.ColCount:=5; AdvStringGrid1.RowCount:=10; end; procedure TForm1.BtnHideClick(Sender: TObject); begin AdvS

我正在TAdvStringGrid中选择某个单元格:

const MyCol=4; MyRow=1; HiddenCol=2; procedure TForm1.FormCreate(Sender: TObject); begin AdvStringGrid1.ColCount:=5; AdvStringGrid1.RowCount:=10; end; procedure TForm1.BtnHideClick(Sender: TObject); begin AdvStringGrid1.HideColumn(2); end; procedure TForm1.BtnSelectCellClick(Sender: TObject); begin AdvStringGrid1.SelectCells(MyCol,MyRow,MyCol,MyRow); end; 常数 MyCol=4; MyRow=1; HiddenCol=2; 过程TForm1.FormCreate(发送方:TObject); 开始 AdvStringGrid1.ColCount:=5; AdvStringGrid1.RowCount:=10; 结束; 程序TForm1.BtnHideClick(发送方:TObject); 开始 AdvStringGrid1.HideColumn(2); 结束; 程序TForm1.BtnSelectCellClick(发送方:TObject); 开始 AdvStringGrid1.选择细胞(MyCol,MyRow,MyCol,MyRow); 结束; 但是,我的问题是,隐藏列后,需要选择的单元格将不会被选择,因为程序看到ColCount现在为4,col 5处的单元格不再存在。如何在不考虑隐藏列的情况下仍选择单元格


通过选择,我的意思是聚焦单元格,并向用户显示所选择的单元格,而不仅仅是读取其字符串值。

根据第57页的TAdvStringGuide v6.1开发者指南,您可以使用grid.AllCells(ACol,ARow)。描述说: “以字符串形式访问网格单元格,而不考虑隐藏的列或行。grid.AllCells返回显示的单元格,即在事件ONGETDEXPTTEXT可能处理真实单元格文本之后。”

要显示选定的单元格,您可以使用它们提供的一些附加功能。在他们的指南第131页:

TAdvStringGrid还提供了一组函数,允许执行真实单元格索引到可见单元格索引的映射,反之亦然。这是通过以下方式提供的:

function RealRowIndex(ARow: Integer): Integer;
function RealColIndex(ACol: Integer): Integer;
返回给定可见列或行索引的实际列或行索引

function DisplRowIndex(ARow: Integer): Integer;
function DisplColIndex(ACol: Integer): Integer;
返回给定实列或行索引的可见列或行索引

因此,我认为您可以通过将上一种方法更改为:

procedure TForm1.BtnSelectCellClick(Sender: TObject);
begin
  AdvStringGrid1.SelectCells(DisplColIndex(MyCol),DisplRowIndex(MyRow),DisplColIndex(MyCol),DisplRowIndex(MyRow));
end;