有一张数据表格式如下
字段名称         字段类型
Cod              varchar
OrderNo          varchar
opendate         datetime
.....
.....要求在DBGrid中当光标移动到opendate字段中,应显示一个Datetimepicker控件,选择相应的日期后自动保存到该条记录中。
我该如何做呢?

解决方案 »

  1.   

    用 EHLIB  里面的 DBGridEh 表格
      

  2.   

    procedure Tfrm_newpj.DBGDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    var
      OldColor, OldFontColor: TColor;
    begin
      if CheckCurrencyField(Column.FieldName) then
      begin
        if (gdFocused in State) then
        begin
          sncDBCurrencyEdit.Left := Rect.Left + DBG.Left+2;
          sncDBCurrencyEdit.Top := Rect.Top + DBG.top+2;
          sncDBCurrencyEdit.Width := Rect.Right-Rect.Left;
          sncDBCurrencyEdit.Height := Rect.Bottom- Rect.Top;
          SetHighLightColor;
          if (sncDBCurrencyEdit.Tag=1) and not sncDBCurrencyEdit.Visible then
            sncDBCurrencyEdit.Visible := True;
        end
        else
          begin
            OldColor := sncDBCurrencyEdit.Color;
            OldFontColor := sncDBCurrencyEdit.Font.Color;
            SetNormalColor;
            DrawCurrencyFrame(DBG.Canvas, Rect, sncDBCurrencyEdit, Column.Field.AsFloat);
            sncDBCurrencyEdit.Color := OldColor;
            sncDBCurrencyEdit.Font.Color := OldFontColor;
          end;
      end;
    end;
      

  3.   

    procedure TFmfilialinfo.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
       if (gdfocused in state) and (column.FieldName='出生年月') then
        begin
          DateTimePicker1.SetBounds(rect.Left + dbgrid1.Left + 1,rect.Top + dbgrid1.Top +1,
                                    rect.Right - rect.Left ,rect.Bottom -rect.Top);
        end;
    end;
      

  4.   

    procedure TFmfilialinfo.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
       if (gdfocused in state) and (column.FieldName='出生年月') then
        begin
          DateTimePicker1.SetBounds(rect.Left + dbgrid1.Left + 1,rect.Top + dbgrid1.Top +1,
                                    rect.Right - rect.Left ,rect.Bottom -rect.Top);
        end;
    end;
      

  5.   

    To: xinshiji(无名) 
       procedure TFmfilialinfo.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
       if (gdfocused in state) and (column.FieldName='出生年月') then
        begin
          DateTimePicker1.SetBounds(rect.Left + dbgrid1.Left + 1,rect.Top + dbgrid1.Top +1,
                                    rect.Right - rect.Left ,rect.Bottom -rect.Top);
        end;
    end;我用了这段代码,怎么没有反应阿,datetimepicker还是在form上
      

  6.   

    To: xinshiji(无名) 
       procedure TFmfilialinfo.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
       if (gdfocused in state) and (column.FieldName='opendate') then
        begin
          DateTimePicker1.SetBounds(rect.Left + dbgrid1.Left + 1,rect.Top + dbgrid1.Top +1,
                                    rect.Right - rect.Left ,rect.Bottom -rect.Top);
        end;
    end;我用了这段代码,怎么没有反应阿,datetimepicker还是在form上
      

  7.   

    参考:
    http://dev.csdn.net/article/53/53439.shtmDBGrid指定列上显示DBComboBox