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);
begin
     if (gdFocused in State) then begin
      Beep;
End;

Open in new window

Paer ToernellAsked:
Who is Participating?
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
0
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.

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

TheDBGRID.Fields[1].FocusControl;

Open in new window

0

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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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);
begin
  Src.First;
  col.PickList.Clear;
  while not Src.Eof do
  begin
    col.PickList.Add(Src.FieldByName(fldName).AsString);
    Src.Next;
  end;
end;

Open in new window


... for DBLookupComboBox  .... there is other solutions - better then using draw event to do something ...
1
Paer ToernellAuthor Commented:
Can the picklist change a indexfield in the target row?
0
Sinisa VukSoftware architectCommented:
What do you mean with
indexfield in the target row
? Change primary key?
0
Paer ToernellAuthor Commented:
Only me found the solution.
0
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
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.