TStringGrid Entry set focus Prob;ems lazarus / 61-Beginners ---------------------------------------------------------------------- JLWest · 2019-01-22 05:09 I have a form with two TStringGrids. I would like to set the Focus on Column 0, Row 1 of each grid. Here is what I found on the org and tried and none seem to work. G1301Grid.Row:=1; G1301Grid.Col:=0; G1301Grid.SetFocus; //G1301Grid.Row :=1; //G1301Grid.Col:=0; //G1301GridSelectCell(self,1,0,cansel);     // Won't compile so I added a period //G1301Grid.SelectCell(self,1,0,cansel);     // Won't Compile //G1301Grid.SetFocus; //G1301Grid.Row:=1; //G1301Grid.SetFocus;              // I can understand why this one doesn't work //G1300Grid.Row:=1;              // as it doesn't have a column specified //G1300Grid.SetFocus; ---------------------------------------------------------------------- howardpc · 2019-01-22 14:28 If you have two string grids, Grid1 (TabOrder=0) & Grid2 (TabOrder=1) then the following code will programmatically put the focus on Grid2, with the cursor in the cell you want, and typing will immediately show in your desired Grid2 cell, with no need to click the grid first. Of course the grids' Options need to be set so they are AutoEdit with goEditing etc. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TForm1 = class(TForm)   Grid1: TStringGrid;   Grid2: TStringGrid;    procedure FormActivate(Sender: TObject);    procedure Grid2Enter(Sender: TObject);    procedure Grid1Enter(Sender: TObject);  end; var  Form1: TForm1; implementation procedure TForm1.Grid1Enter(Sender: TObject);begin  Grid2.Col := 0;  Grid2.Row := 1;end; procedure TForm1.Grid2Enter(Sender: TObject);begin  Grid1.Col := 0;  Grid1.Row := 1;end; procedure TForm1.FormActivate(Sender: TObject);begin  Grid1.PerformTab(True);end; ---------------------------------------------------------------------- JLWest · 2019-01-22 15:16 @howardpc Thanks for the reply. Maybe what I'm trying to do can't be done. I wasn't going to allow direct edit of the grids cells. It's both an accuracy and speed issue. On the form I was going to add three listboxes populated with valid data for the column entries of the grid cells. I would like to move thru the grid columns with the left and right arrow keys. When a cell is highlighted a listbox with the valid entries for that cell would be available. You would move up and down the rows with the up and down arrows. I'm writing a little test program to see if it will work. I'll test your code to see how it works and if I can adapt it to fit. Thanks. ---------------------------------------------------------------------- howardpc · 2019-01-22 20:05 The attached project may give you some pointers.Its based on a nonsense sum-of-integer-digits test to discriminate between 'numeric' data in the stringgrid cells.I also has only one grid. I know your grids have meaningful strings of names or codes in each cell. But not being familiar with your actual data I substituted something simple.  So you'll need to adapt the ideas here. But hopefully you'll have a working code skeleton for what you want to do. ---------------------------------------------------------------------- JLWest · 2019-01-22 20:15 Thanks I'll take a look. Just fdinshed the demp which will explain a lot. Will post it after I get back from an errand. May place it on my gmail drive and post a url for download. ---------------------------------------------------------------------- jamie · 2019-01-22 23:21 I think what you are looking for is the PickList to popup when you select a CELL. ---------------------------------------------------------------------- JLWest · 2019-01-22 23:34 Yea Something Like that. https://drive.google.com/open?id=1k36AHCUk86Iu3K_2rQ1GCZ5jFuqBnS6b Two files: Readme.txt and the Grids Function.7z ---------------------------------------------------------------------- jamie · 2019-01-23 01:58 implement the OnSelectEditor event Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;  var Editor: TWinControl);begin   Editor := TWinControl(TPickListCellEditor.Create(Self));end;                                                                     and use the OnPickList select... P.S.   You need to populate the list of course...  also this is just a test code, you need to create PickListCellEditor elsewhere because each time this event gets called it will keep adding another instance to the list, and this is going to eat memory on you.. create the PickListCellEditor during the startup, place it in your form and use the OnCreate to initiate it.  But in the SelectEditor event, this is where you populate the list each time a cell is selected for edit, each cell maybe different.   Pickeditor.Items.Clear;  Pickeditor.AddItem('someText', nil); etc.. ---------------------------------------------------------------------- JLWest · 2019-01-23 02:42 I'm assuming the 'OnSelectEditor' event is an event on the TstringGrid. And then you code it with:  Editor := TWinControl(TPickListCellEditor.Create(Self)); However, the folloing Var declaration doesn't look right to me. There should be two of the ')' or none I think; var Editor: TWinControl); On picklist select? I'll try it and see what happens. ---------------------------------------------------------------------- jamie · 2019-01-23 22:58 Look, don't create the Control in the OnSelecEditor event, because its going to keep creating new instances of it with the way I showed you, that was just a quick and simple test not intended for actual use..  Create a instance of the Editor elsewhere like in the Form.Create one time and then each time the OnSelectEditor is triggered you set it and populate it with the correct content that fits the current situation. ---------------------------------------------------------------------- wp · 2019-01-24 00:00 The picklist cell editor is already built into the grid (http://wiki.l azarus.freepascal.org/Grids_Reference_Page#Grid_Cell_Editors, http://w iki.lazarus.freepascal.org/Grids_Reference_Page#Example:_How_to_set_a_ custom_cell_editor) See the attached demo. ---------------------------------------------------------------------- JLWest · 2019-01-24 00:48 @WP I think I understand this a lot better now. How you highlight the cell. The picklist would work for some cells but some have multi- select entries and need to be formatted a specific way. But thank you for the simple demo. I'll try working with this. ---------------------------------------------------------------------- jamie · 2019-01-24 01:17 Although you can do as WP showed you and it makes it easier of course however, if  you write a app like I am currently hacking with, I preload picklist and have several of them on a row when I select a ROW.  I do this so I can drop down one list, pick something out of it and then move over to another cell on the same row and drop that one and then insert that item. This way I have different Picklist editor instances.  I know I can also do this in the background of course with stringlist but this means I have to keep reloading a single picklist editor.  But you can code the way you wish, that is what makes it so wonderful.