Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.pascal.delphi.misc > #214

Re: A DBGrid with a clickable button

From "Stark" <franco.jommi@tin.it>
Newsgroups comp.lang.pascal.delphi.misc
References <4f37e08c$0$1380$4fafbaef@reader2.news.tin.it> <LgSZq.19832$E07.16639@newsfe10.iad>
Subject Re: A DBGrid with a clickable button
Date 2012-02-13 00:09 +0100
Message-ID <4f384694$0$1389$4fafbaef@reader2.news.tin.it> (permalink)
Organization TIN.IT (http://www.tin.it)

Show all headers | View raw


"Jamie" <jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> ha scritto nel 
messaggio news:LgSZq.19832$E07.16639@newsfe10.iad...
> Stark wrote:
>
>>
>> I found a number of examples on the web on how to add a CheckBox in a 
>> DBGrid column, but I need a Button. Inspired by those examples, I tried 
>> by myself with little success. In my test project I get a button in a 
>> boolen field (it could be any field), but the button remains pushed when 
>> clicked, and only the click on a button in another row will reset it 
>> raised. I cant find a remedy ? This is the OnDrawColumnCell I wrote:
>>
>> procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: 
>> TRect;
>>  DataCol: Integer; Column: TColumn; State: TGridDrawState);
>> begin
>>  with Sender as TDBGrid do
>>  begin
>>     if Column.Field.DataType = ftBoolean then
>>     begin
>>       Canvas.FillRect(Rect);
>>       DrawFrameControl(Canvas.Handle, Rect, DFC_BUTTON, DFCS_BUTTONPUSH);
>>    end;
>> end;
>> end;
>
>  I see a potential problem here, this above code does not say when at what 
> point does the event get called? After reviewing the events that
> are available to you (TDBGrid), it is my best guess that this event above 
> only gets called after the mouse is released and not when it is
> pushed down.
>
>   How ever, a simple test can determine this, if you press and hold the 
> mouse key down and see your little button drawn, then you are in luck :)
>
>   You can stash the RECT value away and process the WM_KEYUP message in 
> the form that contains this DBgrid..  When you process this message, check 
> to see if the stashed RECT is valid? IN other words, its not set to a 0 
> value, if so then process the graphics code needed to undo the button box 
> and then clear the RECT value. You could also test for the
> currently active control while there to save time.
>
>   You cold also simply assign a Button over that area and then process the 
> DB code yourself in the button event. Set your own image on the button. 
> They're a few ways :)
>
>
> Jamie
>
>
I am not sure I understand your comments. I'll try to explain what I did: In 
a form I have a DBGrid and a Table as Datasource. I want one of the columns 
to display a button, rather then its content. So I set DefaultDrawing to 
true and paint the button with DrawFrameControl. The DBGrid1 
OnDrawColumnCell event is called initially when the DBGrid associated table 
is opened and whenever any cell is entered or the grid scrolled. The button 
shows correctly. But clicking on it, the button is repainted pushed and does 
not raise if clicked again. If I click on the button in another row, this 
will show pushed and the previous will raise. If you have an idea on how to 
correct this behaviour, can you show an example ? Thanks 

Back to comp.lang.pascal.delphi.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

A DBGrid with a clickable button "Stark" <franco.jommi@tin.it> - 2012-02-12 16:54 +0100
  Re: A DBGrid with a clickable button Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> - 2012-02-12 12:07 -0500
    Re: A DBGrid with a clickable button "Stark" <franco.jommi@tin.it> - 2012-02-13 00:09 +0100
      Re: A DBGrid with a clickable button Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> - 2012-02-12 21:01 -0500
        Re: A DBGrid with a clickable button "Stark" <franco.jommi@tin.it> - 2012-02-13 14:48 +0100
          Re: A DBGrid with a clickable button GS <gs@somewhere.net> - 2012-02-13 10:40 -0500
          Re: A DBGrid with a clickable button Jamie <jamie_ka1lpa_not_valid_after_ka1lpa_@charter.net> - 2012-02-13 17:48 -0500
            Re: A DBGrid with a clickable button "Stark" <franco.jommi@tin.it> - 2012-02-14 12:11 +0100
      Re: A DBGrid with a clickable button Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2012-02-13 09:50 +0100

csiph-web