简体   繁体   English

如何将TGrid的'selected'属性设置为-1

[英]How to set 'selected' property of TGrid to -1

I am using a FMX.Grid.TGrid in which a user can select complete rows. 我正在使用FMX.Grid.TGrid ,用户可以在其中选择完整的行。 In some cases I want to reset this selection. 在某些情况下,我想重置此选择。 If I do this with grid.selected = -1 or with grid.selectRow(-1) the selection is removed from the grid but grid.selected is set to '0' (in TCustomGrid.SelectCell ), which is the first row. 如果我使用grid.selected = -1grid.selectRow(-1)进行选择,则选择将从网格中删除,但grid.selected设置为“ 0”(在TCustomGrid.SelectCell ),这是第一行。

How can i reset the selection so that the property grid.selected is '-1'? 如何重置选择,以便grid.selected属性为“ -1”?

I checked code of FMX library I did tiny class helper, which allow you to get direct access to private property which are store value of selected row. 我检查了FMX库的代码,并做了微小的类帮助程序,该程序使您可以直接访问作为选定行存储值的私有属性。 Tested on Delphi XE8. 在Delphi XE8上测试。 This code will work correctly, even if you have options "AlwaysShowSelection" enabled. 即使您启用了“ AlwaysShowSelection”选项,此代码也将正常工作。

  TMyG = class helper for TCustomGrid
  public
    procedure DoSomethingStrange;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.btnReadSelectionClick(Sender: TObject);
begin
  Caption := Grid1.Selected.ToString;
end;

procedure TForm1.btnResetSelectionClick(Sender: TObject);
begin
  Grid1.DoSomethingStrange;
end;

{ TMyG }

procedure TMyG.DoSomethingStrange;
begin
  Self.FSelected := -1;
  Self.UpdateSelection;
end;

如果您的目的不是在网格中显示选定的行,则可以通过将焦点放在另一个组件上来使其散焦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM