DrawColumnCell State fails

I have a tDbgrid where i insert a lookupbox, here replaced by "beep". Problem is that the first time a user clicks in the column the  "State: TGridDrawState" is blank, that  "gdFocused in State" is false when it should be true and the user have to click some where else and a second time on the cell to get the action going. Any ideas why State not is gdFocused the first time?

procedure TfrmLineDocument.dbgInvLinesDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
     if (gdFocused in State) then begin

Open in new window

Paer ToernellAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
you have a syntax error
there is an end; missing in your code

first, the grid receives focus
and then it depends on the options
focused, selected and edit mode has to be checked for drawing
onenter and onleave are used to open and close the combo

the first time, the column is not focused, this is correct
it is only after the click that the column gets focus

you have minimized the code way too much to be able to help
Paer ToernellAuthor Commented:
The first event is a normal update, correct. Problem is the first update afterthe user  have selected the cell receives no "(gdFocused in State)". The TGridDrawState is empty, no state at all.

Paer ToernellAuthor Commented:
Found a workaround. Change focus in the activate event of the form to any field exept the first.


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Sinisa VukSoftware architectCommented:
As I can see - you use example from delphi.about.com for displaying DBLookupComboBox inside a cell of a DBGrid.
I think it is easier to use build in PickList for it. Call my procedure FillDataList after lookup dataset is open:
FillDataList(DBGrid1.Columns.Items[1], ADODataSet2, 'FieldName1');
procedure FillDataList(col: TColumn; Src: TDataSet; fldName: String);
  while not Src.Eof do

Open in new window

... for DBLookupComboBox  .... there is other solutions - better then using draw event to do something ...
Paer ToernellAuthor Commented:
Can the picklist change a indexfield in the target row?
Sinisa VukSoftware architectCommented:
What do you mean with
indexfield in the target row
? Change primary key?
Paer ToernellAuthor Commented:
Only me found the solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.