title: How works the event DrawColumnCell from delphi 7?
body: <p>I'm using this event (DrawOnColumnCell) for put a datetimepicker in a DBGrid, more precice in a field called &quot;fechaprobablealta&quot;. This grid have a client datasource that have a providerDataSet and this take data from a SQLDataSet.
  I can draw a datetimepicker good until that i tried update the clientdataset. Here a have a error from &quot;Access violation at address&quot; that i couldn't resolve. Here i puts the code:</p>
  <pre><code>procedure TfmForm.gdGridDrawColumnCell(Sender: TObject;
    const Rect: TRect; DataCol: Integer; Column: TColumn;
    State: TGridDrawState);
  begin
    if ckCasosAlta.Checked then
    begin
      dtFechaProbableAlta.Visible:=False;
      if cDataSet.FieldByName('fechaalta').Value &lt;&gt; null then
      begin
        gdGrid.Canvas.Brush.Color:=clLime;
        gdGrid.DefaultDrawColumnCell
        (Rect, DataCol, Column, State);
      end;
    end
    else
    begin
      if (gdSelected in State) then
      begin
        if (Column.Field.FieldName = 'fechaprobablealta') then
        begin
          with dtFechaProbableAlta do
          begin
            Left:= Rect.Left + gdGrid.Left+1;
            Top:= Rect.Top + gdGrid.Top+1;
            Width:= Rect.Right - Rect.Left+ 2;
            Height:= Rect.Bottom - Rect.Top +2;
            Date:= Column.Field.AsDateTime;
            Visible:=True;
          end;
        end;
      end;
    end;
  end;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/e4NJ0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e4NJ0.png" alt="enter image description here" /></a></p>
  <p>When chekcbox is checked:</p>
  <p><a href="https://i.stack.imgur.com/2xsbw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2xsbw.png" alt="" /></a></p>
  <p>here the metod when press the checkbox:</p>
  <pre><code>procedure TfmForm.ckCasosAltaClick(Sender: TObject);
  begin
    if ckCasosAlta.Checked then
    begin
      chkCasosProbableAlta.Checked:=False;
      cDataSet.Close; //ClientDataSet
      qDataSet.CommandText:=  //SQLDataSet
                              //SQL QUERY
                              ;           
    end
    else
    begin
          cDataSet.Close; //ClientDataSet
      qDataSet.CommandText:=  //SQLDataSet
                              //SQL QUERY
                              ;    
    end;
    cDataSet.Open;
    cDataSet.Refresh;
  end;
  </code></pre>
  <p>This works good in begin and too when press the checkbox &quot;ckCasosAlta&quot;,  (the client dataset is closed, change the query, open again and refresh) where hide the datetimepicker and paint the cell called &quot;fechaalta&quot; of green. The problem come when come back to press the checkbox (cheked:= false). The client data set do the same proces and stay like at begin (same sql query). Here have the problem. I have a &quot;Acces violation at adress..&quot;.</p>
  <p><a href="https://i.stack.imgur.com/DQMA5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DQMA5.png" alt="enter image description here" /></a></p>
  <p>So i need to know how works the event DrawColumnCell from a dbgrid to be able to debug this problem or know the problem in this case</p>