Recent

Author Topic: StringGrid question about onkeypress events  (Read 3628 times)

wpflum

  • Sr. Member
  • ****
  • Posts: 287
StringGrid question about onkeypress events
« on: February 04, 2015, 07:27:05 pm »
I'm trying to use a StringGrid object for invoice entry, basically the first column is item code the next is description, quantity, price and so on.  I would have used a grid of Tedits but I'm trying to pick up more from Lazarus/Delphi so after a bit of looking the StringGrid seemed like it would make things easier, if you have a better suggestion let me know. 

Anyway the issue I have is that I have to force the movement in the grid to horizontal only meaning first the item code cell then the quantity shell, price and so on and if the user clicks out of the current line our uses the cursor keys to go up or down then the program has to determine if they are at a point where it is allowed or keep the focus on the current cell.  I've done thing like this before with individual tedit 'cells' where the onkeypress checks what key is pressed and decides based on where on the screen the current object is whether or not to allow movement but in the StringGrid I don't see the cursor keys being captured just normal keys.  Is this a bug or, and this is more likely, do I have something screwed up?    I've tried this with the forms keypreview set to true and false and get the same thing so if it isn't a bug then I'm guessing that I'm missing a setting for the StringGrid object that is not letting the onkeypress event see the cursor keys.

Ideas?
« Last Edit: February 04, 2015, 09:07:36 pm by wpflum »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: StringGrid question about onkeypress events
« Reply #1 on: February 04, 2015, 09:41:33 pm »
Have a look at lazarus/examples/gridexamples/columneditors/stringgrideditor.lpi,
especially the OnValidateEntry code.
This event will swallow keystrokes that attempt to alter cell focus if the edited text does not meet the requirements you specify in the code for that event.

wpflum

  • Sr. Member
  • ****
  • Posts: 287
Re: StringGrid question about onkeypress events
« Reply #2 on: February 09, 2015, 07:16:02 pm »
I took a look and except for the one masked text entry cell all the other cells allowed the cursor keys to move to another cell without trapping the keys at all.  The masked cell seemed to work but for the life of me I couldn’t see how they did it. 

I just dropped using a stringgrid completely and went to separate tedits that I can create on the fly and then set the onkey event to decide if the cursor keys are allowed to stay depending on the content of the existing line.

Thanks for the info though, I'll keep it in mind for future projects.
 

 

TinyPortal © 2005-2018