tags:

views:

92

answers:

1

Hi, I have (in D2010) a TDrawGrid on my form. Im handling my OnDrawCell, OnSetEditText, OnSetEditText etc alls gfine there.

If however in the specific situation that you go in a cell that has some text, highlight the text in its entirity, then type some character to replace. Now the OnSetEditText event fires twice in a row from one keypress, firstly with a blank string, then again with a string containing the character you type. Is this correct or a bug? I would have expected to just get the event fired once with the string containing my single character typed.

I am using OnSetEdit text to set other class properties which does stuff like validation, so when the above situation causes my other code to consider momentarily my class properties to be invalid, before imediately being set back to valid again on the 2nd fire, its still having undesriable consequences though and i want to stop that 1st event firing, or get the bets workaround I can.

Now whilst on the subject of grids, may I appeal to you folks for an helpful tips in the folling things. I am fairly new to deplhi from c# (I'm going the other way!) but Im finding the docs to be pretty thin on the ground, and am getting surprisingly limited results googling for things, so your help is really appreciated.

1) Custom Inplace Editors for TDrawGrid - any tips or good links appreciated! 2) For custome inplace editors, am i better off with TDrawGrid or descending my own control from TCustomGrid and going from there? 3) TCustomGrid. I am getting nowhere here... If I create a new component and descend from TCustomGrid I just get an 'abstract error' when i place it my form. Therefore further experimentation is very much canclled - an advice on just even getting started with TCustomGrid appreciated!

My plan is first to get combo boxes (in virtual mode) working as cell editors. Thats a standard VCL control. Afterwards I plan to create my own control based around a virtual combobox but with a search thing at the top to filter the list down (a bit like in the Delphi IDE Tool pallette), and use this component as inlace editor if possible. Im a fair way off that right now! Thanks all

Edit: Remy - Here are my two call stacks from beak point in OnSetEditText. Left is first fire with the empty string, right is 2nd fire with correct string value. The 5 truncated lines in the middle are all references to comctl32.dll in both. Ty.

Click here for call stack

A: 

The OnSetEditText event is fired whenever the inplace editor's contents are updated for any reason, when a drop-down editor is closed after selecting a different value, a drop-down editor is double-clicked on, or a drop-down editor's RestoreContents() method is called. So you very likely are getting multiple actions updating the editor one after the other. I suggest you put a breakpoint inside the TCustomDrawGrid.SetEditText() method and see what the call stack looks like each time the event is being fired.

Regarding #2, it does not matter what you derive from. Any TCustomGrid descendant can have a custom inplace editor. Simply override the virtual CreateEditor() method.

Regarding #3, if you are getting an abstrct error when deriving from TCustomGrid directly, then you did not override its abstract methods correctly.

A grid already natively supports a drop-down inplace editor that mimics a combobox. Look at the TInplaceEditList class. You can use the OnGetPickListItems event to fill in the editor with values. Also, have a look at how TValueListEditor implements its custom editors.

Remy Lebeau - TeamB
Thanks very much Remy, that gives me some interesting leads to go on.About the original question - the TDrawGrid double fire of OnSetEditText. I took screenshots of my stacks on both events, aside from the value of the string passed in, its 100% identical. I understand what your saying about other editors etc interfering, but there is none. I reduced it all down to a blank TDrawGrid, i hand the DrawCell and Get/SetEdittext in the simplest way possible, and absolutely nothing more. No drop down editors or anything else is there, its a stripped down as it can be. I just have goEditing true.
csharpdefector
Ahah. I only just realised you can actually see all the source code in of the units! Like grids.pas! Doh. My life just got a WHOLE lot easier :) Still getting the double event fire - it just seems that if the select text of a cell and start typing then the default behaviour of TDrawGrid is to fire off 2 events, the first having an empty string. That dont seem right to me.
csharpdefector
Can you provide the actual call stack screenshots?
Remy Lebeau - TeamB
Yes Sir, theres now a link in my orig question. Ty.
csharpdefector
The call stack shows that the inplace editor is reacting to EN_CHANGE notifications being issues by the OS, so the edit field really is operating on two separate changes - clearing the selected Text, followed by the insertion of the typed character. There is not much you can do about that since it is the OS issuing separate notifications. I would suggest moving your validation logic out of the OnSetEditText event directly. Have it call PostMessage() to queue a custom window message, and then do the validation inside that message handler using whatever the current Text is...
Remy Lebeau - TeamB
... that message handler can also remove duplicate posted messages from the message queue, so you are only validating once per group of changes, and the next change after the validation will queue another delayed validation.
Remy Lebeau - TeamB
Thank you very much indeed for you expert advice. I shall implement the solution you suggest. ty
csharpdefector