Mike Warren 2 Posted June 30, 2023 How do I access the InplaceEditor of a TStringGrid? Specifically, I'll like to respond to KeyDown and KeyUp. The first task I need is to convert every entered character to uppercase, but I expect to need to do more later. Share this post Link to post
Lars Fosdal 1792 Posted June 30, 2023 One option is the OnSetEditText event. https://docwiki.embarcadero.com/Libraries/Sydney/en/Vcl.Grids.TCustomDrawGrid.OnSetEditText Share this post Link to post
Mike Warren 2 Posted June 30, 2023 Thanks for the reply Lars. Am I mistaken that I can't find OnSetEditText in FireMonkey? It seems to be VCL only. Share this post Link to post
Lars Fosdal 1792 Posted June 30, 2023 5 minutes ago, Mike Warren said: Thanks for the reply Lars. Am I mistaken that I can't find OnSetEditText in FireMonkey? It seems to be VCL only. Argh, Mike - my bad. I was speaking from a VCL point of view - not noticing that you posted in the FMX section. Not the first time I've made that mistake. Share this post Link to post
Lars Fosdal 1792 Posted June 30, 2023 What about https://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Grid.TStringGrid.OnEditingDone ? Share this post Link to post
Mike Warren 2 Posted June 30, 2023 Unfortunately, I want to show this as the user types. Share this post Link to post
Lars Fosdal 1792 Posted June 30, 2023 Doesn't the grid get OnKeyDown events once you are in the cell editor? https://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Controls.TControl.OnKeyDown Share this post Link to post
programmerdelphi2k 237 Posted June 30, 2023 @Mike Warren question: doesn't the "inplace editor" have the mission of showing a "custom" control to edit the value of what is shown in the grid? That is, when associating the variable "Control" to a new control, couldn't you simply access the properties of this "control"? Quote procedure TForm1.StringGrid1CreateCustomEditor(Sender: TObject; const Column: TColumn; var Control: TStyledControl); function MyComboBoxToGridCustomEditor(AOwner: TComponent { TForm - Form1 } ): TComboBox; begin result := TComboBox.Create(AOwner); // now, you access the properties/events/etc.. // result.Items.AddStrings(MyAllEnumsNames); // result.OnChange := Form1.MyComboBoxChange; end; procedure TForm1.Grid1CreateCustomEditor(Sender: TObject; const Column: TColumn; var Control: TStyledControl); begin // Control is nil (???) = using default controls as defined on grid // Sender is TStyledGrid; // if Column.Index = 1 then // now using my ComboBox Control := MyComboBoxToGridCustomEditor(Self); // destroyed when out scope this procedure... end; 1 Share this post Link to post
Alexander Halser 26 Posted July 5, 2023 Quote No, it doesn't. I was about to suggest to create a custom inplace editor. But the form that contains the TStringGrid does get KeyDown notifications, even when editing content. Out of curiosity, I wanted to know the internal structure of the grid, when it's editing. procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); var ctl: tfmxobject; s: string; begin if key = vkF5 then begin ctl := activecontrol; while ctl <> form2 do begin s := '> ' +ctl.classname + S; ctl := ctl.Parent; end; showmessage(s); end; end; It says: TStringGrid > TGridScrollContent > TDefaultEditor So if you check the OnKeyDown on form level and detect that ActiveControl is a TDefaultEditor with a TStringGrid as grandparent, you should be all set. Aren't you? Share this post Link to post
programmerdelphi2k 237 Posted July 5, 2023 (edited) the "OnKeyDown" event works, you need to be on column desired. type TForm1 = class(TForm) StringGrid1: TStringGrid; // ComboBox1: TComboBox; not necessary because will be create on-the-fly StringColumn1: TStringColumn; StringColumn2: TStringColumn; StringColumn3: TStringColumn; Memo1: TMemo; procedure StringGrid1CreateCustomEditor(Sender: TObject; const Column: TColumn; var Control: TStyledControl); private function MyComboBoxToGridCustomEditor(AOwner: TComponent { TForm - Form1 } ): TComboBox; { Private declarations } procedure MyComboBoxKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); ... implementation {$R *.fmx} procedure TForm1.MyComboBoxKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin Caption := Format('%s, Key=%d, KeyChar=%s ', [TimeToStr(now), Key, KeyChar]); end; function TForm1.MyComboBoxToGridCustomEditor(AOwner: TComponent { TForm - Form1 } ): TComboBox; begin result := TComboBox.Create(AOwner); // now, you access the properties/events/etc.. // result.Items.AddStrings(['hello', 'world']); // result.OnKeyDown := MyComboBoxKeyDown; end; procedure TForm1.StringGrid1CreateCustomEditor(Sender: TObject; const Column: TColumn; var Control: TStyledControl); begin // Control is nil (???) = using default controls as defined on grid // Sender is TStyledGrid; // if Column.Index = 0 then // now using my ComboBox Control := MyComboBoxToGridCustomEditor(Self); // destroyed when out scope this procedure... end; Edited July 5, 2023 by programmerdelphi2k Share this post Link to post
Mike Warren 2 Posted July 7, 2023 Thanks for the ideas. I decided to go with the custom editor because for other cells I need different types of editing. Share this post Link to post
programmerdelphi2k 237 Posted July 8, 2023 (edited) @Mike Warren dont forget: you can use "CharCase" property := ecUpperCase to get uppercase without any workaround Edited July 8, 2023 by programmerdelphi2k Share this post Link to post
Mike Warren 2 Posted July 8, 2023 Except that in FMX: [dcc32 Error] uAPMain.pas(1103): E2003 Undeclared identifier: 'ecUpperCase' Share this post Link to post
programmerdelphi2k 237 Posted July 8, 2023 on OnKeyPress / OnKeyDown event ... key := uppercase( key ); // keyChar Share this post Link to post