0
procedure TFormMain.CaseListMyShares(uri: String);
var
  i: Integer;
begin
  myShares := obAkasShareApiAdapter.UserShares(uri);
  MySharesGrid.RowCount:= Length(myShares) +1;
  MySharesGrid.AddCheckBoxColumn(0, false);
  MySharesGrid.AutoFitColumns;

  for i := 0 to Length(myShares) -1 do
  begin
    MySharesGrid.Cells[1, i+1]:= myShares[i].patientCase;
    MySharesGrid.Cells[2, i+1]:= myShares[i].sharedUser;
    MySharesGrid.Cells[3, i+1]:= myShares[i].creationDate;
    MySharesGrid.Cells[4, i+1]:= statusText[StrToInt(myShares[i].situation) -1];
  end;
end;

I want to create an invisible column to myself. I have to know row's identifier to make some operations with REST API. But end-user does not need to see this identifier on table. How can i create an invisible column ?

myShares[i].identifier which i want to hide on every row. Is that possible ? Using TAG or anything ?

Nevermore
  • 1,663
  • 7
  • 30
  • 56
  • 2
    Don't use your grid as your data storage. Store the data elsewhere, and use the grid just to view it. Even better, use a virtual list view. – David Heffernan Dec 14 '17 at 13:29
  • @DavidHeffernan i am using grid just to view it. I store my data in remote server. They communicate with Rest Api. Delphi users request GET data from remote server and fill the grid. But when the user need to update any row on grid, they need to know id. But i am not showing id to user in grid. I want to store every row's id in background and for example when the user try to update any row, i request an update to remote server using that hidden id. So how can i tag each row with id ? – Nevermore Dec 14 '17 at 13:34
  • Sounds like a job for a DBGrid and ClientDataset. The ClientDataSet has all fields, the DBGrid shows only the columns you want. – GuidoG Dec 14 '17 at 13:36
  • You aren't using it just to view. You are wanting to out extra hidden data into it. By definition that's not for viewing. – David Heffernan Dec 14 '17 at 13:38
  • @GuidoG yes but i can not connect DB directly. There is a remote server to handle this. I use the rest API to communicate between program and DB. David Heffernan i understand now, but i could not find virtual list view in tool palette. Could you explain a little more ? – Nevermore Dec 14 '17 at 13:42
  • I did not say you need to connect to the DB directly. You can store the data you recieve from the rest API into a ClientDataSet in stead of in a stringgrid. A ClientDataSet can work without data connection and you can still couple a DBGrid to it – GuidoG Dec 14 '17 at 13:45
  • David already said you should not store the data in the stringgrid, but elsewhere. A ClientDataSet is one option you can use to store your data. It does not need a connection to a database but can work in memory – GuidoG Dec 14 '17 at 13:47
  • 4
    Use a `TListView` in virtual mode, see [How to fast read and write in listview in delphi?](https://stackoverflow.com/a/4232718/576719). If you want to explore what every Delphi user should have in their toolbox, see [TVirtualTreeView](http://www.soft-gems.net/index.php/controls/virtual-treeview) – LU RD Dec 14 '17 at 16:54
  • I don't recognize `AutoFitColumns` as a method or property of a Delphi `TStringGrid`. So what is `MySharesGrid` actually? What is `myShares`? Does it hold the id? Just don't copy it to the grid, fetch the id from `myShares` when you need it. Better still as others pointed out, use a `TListView` in virtual mode or alternatively a `TDrawGrid`. – Tom Brunberg Dec 14 '17 at 19:44
  • 1
    Set the column width to 0 – Dave Nottage Dec 14 '17 at 20:58

2 Answers2

1

To assign the identifier:

MySharesGrid.Objects[0, i+1] := TObject(myShares[i].identifier)

To access the identifier (e.g. OnClick):

Integer(MySharesGrid.Objects[0, MySharesGrid.Row])
MaGiC
  • 311
  • 1
  • 4
1

To answer the question, assign its ColWidths to -1, thusly:

StringGrid1.ColWidths[4] := -1;

You can show it again by setting that back to a positive value.

This is not about using a StringGrid to store data, but for the User Interface to show/hide columns - like a Collapse speedbutton in the title, with a corresponding Show All button to restore it.

Jon
  • 812
  • 2
  • 11
  • 18