Finalise input entry in string grid lazarus / 31-LCL ---------------------------------------------------------------------- Jonas Maebe · 2015-02-10 10:06 Hi, I have Form A with a string grid, and Form B with a button that processes the data entered in the string grid. The problem is that if you start editing a cell in the string grid and don't press enter or move the focus, then if you click the button on the other form it will still use the old data. This is logical, but my question is: what is the best way to force- finish any potential data entry that's in progress in the string grid when the button is clicked? I've though of sending a VK_RETURN to the string grid (but if no editing is in progress, that will start editing the currently selected cell), or maybe change the focus of the currently selected cell (and then back to the original one to restore the original state), but those all seem like hacks. Thanks. ---------------------------------------------------------------------- Laksen · 2015-02-10 10:09 Doesn't it already lose focus once you click the button on the other form? ---------------------------------------------------------------------- Jonas Maebe · 2015-02-10 10:11 The grid and its form lose focus, but the cell that was being edited stays in editing mode. Edit: and its OnValidateEntry handler isn't called either. Edit 2: I should have mentioned in my original post that I change another data structure based on what is entered in the string grid inside this OnValidateEntry handler (if the entered data was valid), and it's this other data structure that is used by Form B. So as long as the OnValidateEntry handler is not called, I don't notice any changes. The string data in the grid may actually already have been changed. Sorry about the incomplete information. ---------------------------------------------------------------------- skalogryz · 2015-02-10 13:42 It sounds like you need to call "ResetEditor" method during DeActivate event of Form A. One problem is that it is a protected method. The good part is that it's part of TCustomGrid, thus you can legally call it for any descendant grid. On the other hand VK_RETURN should work (with validation event), if you use EditorKeyPress(Grid1.Editor, VK_PRess) method. ---------------------------------------------------------------------- Jonas Maebe · 2015-02-12 14:01 ResetEditor cancels the current input and restores the old one. Sending VK_RETURN to the editor advances the selection in the grid to the next cell (both when you were editing and when not). Neither is really ideal... ---------------------------------------------------------------------- Jonas Maebe · 2015-02-12 14:08 Sorry, I must have made a mistake in entering a partial value when I first tested ResetEditor (so my validate method restored the previous value). ResetEditor does do what I want. Thanks! ---------------------------------------------------------------------- skalogryz · 2015-02-12 14:40 Great! I guess when TGrid interface was developed nobody ever considered the need to "manually finish editing". It might be a good idea (and a patch?) to have either ResetEditor or some other method to manually finish editing as a public method. ---------------------------------------------------------------------- marcov · 2015-02-12 19:19 (if you need a good name VST calls it canceleditnode) ---------------------------------------------------------------------- skalogryz · 2015-02-12 20:31 What is VST?  V..??..ShellTree ? I presume suffix "node" doesn't apply to a Grid. It's using "Cell" instead... something like StopEditCell() or EditorClose() As Jonas mentioned earlier (referring to need of OnValidateEntry), the method should allow to specify if editing should just cancel or attempt to apply the current value of the editor. So I'm not sure if having "cancel" in the method name is good. ---------------------------------------------------------------------- taazz · 2015-02-13 09:18 Quote from: skalogryz on February 12, 2015, 09:31:22 pmWhat is VST?  V..??..ShellTree ? VirtualStringTree