在ehlib的DBGridEh输入数据时,如何控制一定要先输入某栏位,才能输入另外一个栏位??

解决方案 »

  1.   

    if (DBGridEh1.SelectedField.FieldName ='后输入的字段') and 
       (DBGridEh1.datasource.dataset.fieldbyname('须先输入的字段').isnull) then
    begin   
      for i:=0 to DBGridEh1.Columns.Count -1 do
      begin
       if DBGridEh1.Columns[0].FieldName ='须先输入的字段' then
       begin
          DBGrid1.SelectedIndex :=i;
          break;
       end;
      end;
    end;
      

  2.   

    DBGridEH的每列都有ReadOnly属性,控制一下如果那个该输入的列输入了数据才允许另一列可读就是
      

  3.   

    Anylib,创意、自由、灵活的体现,超强的报表功能,独特的双数据源连接,全功能的表格组件,它带给你的是轻松,美妙!http://www.anylib.com
      

  4.   


      改一下DBGridEh类的代码,生成一个OnBeforeCellExit事件,在这个事件判断是否输入数据:  TDBGridEh = class(TCustomDBGridEh)
      private
       
      ....  protected
       procedure DefaultDrawColumnCell(const Rect: TRect;DataCol: Integer; Column: TColumnEh; State: TGridDrawState); overload;
        procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override{virtual};
        procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
        procedure KeyPress(var Key: Char);override;
        procedure KeyDown(var Key: Word; Shift: TShiftState); override{virtual};
        procedure KeyUp(var Key: Word; Shift: TShiftState); override{virtual};{´¥·¢×Ô¶¨Òåʼþ£ºBeforeCellExit}
    procedure TDBGridEh.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if((CurCell.X <> Col)or
          (CurCell.Y <> Row))and
           (Firstfocused=false)then
      begin{&acute;&yen;·&cent;×&Ocirc;&para;¨&Ograve;&aring;&Ecirc;&Acirc;&frac14;&thorn;BeforeCellExit}
        if Assigned(OnBeforeCellExit) then{×&Ocirc;&para;¨&Ograve;&aring;&Ecirc;&Acirc;&frac14;&thorn;}
            fOnBeforeCellExit(self,CurCell.Y,CurCell.X);
      end;
      inherited;
    end;{&acute;&yen;·&cent;×&Ocirc;&para;¨&Ograve;&aring;&Ecirc;&Acirc;&frac14;&thorn;&pound;&ordm;BeforeCellExit}
    procedure TDBGridEh.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      inherited;
      Firstfocused:=false;
    end;procedure TDBGridEh.KeyDown(var Key: Word; Shift: TShiftState);
    var
      i:integer;
    begin
      if Key=VK_DOWN then
      begin
        i:=DataSource.DataSet.RecNo;
        if i=-1 then
          i:=DataSource.DataSet.RecordCount;
        if i=DataSource.DataSet.RecordCount then
        Abort;{Key:=0;}
      end;
      if(Key=VK_UP)or
         (Key=VK_DOWN)or
          (Key=VK_LEFT)or
           (Key=VK_RIGHT)or
            (Key=VK_TAB)or
             (Key=VK_RETURN)then
      begin
        if((CurCell.X <> Col)or
            (CurCell.Y <> Row))and
             (Firstfocused=false)then
        begin{&acute;&yen;·&cent;×&Ocirc;&para;¨&Ograve;&aring;&Ecirc;&Acirc;&frac14;&thorn;BeforeCellExit}
          if Assigned(OnBeforeCellExit) then
              fOnBeforeCellExit(self,CurCell.Y,CurCell.X);
        end;
      end;
     inherited;
    end;procedure TDBGridEh.KeyUp(var Key: Word; Shift: TShiftState);
    begin
      inherited;
      DoKeyUped(Self,Key,Shift);
      Firstfocused:=false;
    end;procedure TDBGridEh.DefaultDrawColumnCell(const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
    begin
      //inherited;
      {&Egrave;&ccedil;&sup1;&ucirc;&Ograve;&ordf;&raquo;&shy;&frac12;&sup1;&micro;&atilde;&pound;&not;&frac34;&Iacute;&Egrave;&Atilde;DBGrid&frac12;&oslash;&Egrave;&euml;±à&frac14;&shy;×&acute;&Igrave;&not;}
      if(gdFocused in State) then
      begin
        //&Egrave;&ccedil;&sup1;&ucirc;&Ecirc;&Ccedil;&frac12;&oslash;&Egrave;&euml;&Ograve;&raquo;&cedil;&ouml;&ETH;&Acirc;&micro;&Auml;Cell
        if((CurCell.X <> DataCol{Col})or
           (CurCell.Y <> Row{DataSource.DataSet.RecNo}))then
        begin
          {&Igrave;×&ordm;&Uacute;&iquest;ò}
          if fShowRect then
          begin
            EditorMode := True;
            AddBox;
              {&Egrave;&laquo;&Ntilde;&iexcl;&AElig;&auml;&Ouml;&ETH;&micro;&Auml;×&Ouml;·&ucirc;}
              CurCell.tag := 0;
              GetWindowRect(InPlaceEditor.Handle,CurCell.r);
              SendMessage(InPlaceEditor.Handle,EM_SETSEL,0,1000);
          end;
          {&cedil;ü&ETH;&Acirc; Row,col }
          CurCell.X := DataCol{Col};
          CurCell.Y := Row{DataSource.DataSet.RecNo};
        end else
        begin {&Otilde;&yacute;&sup3;&pound;&Iuml;&Ocirc;&Ecirc;&frac34;×&acute;&Igrave;&not;&micro;&Auml;Cell}
          inherited;
        end;
      end;
    end;   
        
     
      

  5.   


      先定义:  TCurCell = Record {&micro;±&Ccedil;°&frac12;&sup1;&micro;&atilde;Cell&micro;&Auml;&Icirc;&raquo;&Ouml;&Atilde;}
        X : integer; {&Oacute;&ETH;&frac12;&sup1;&micro;&atilde;Cell&micro;&Auml;ColumnIndex}
        Y : integer; {&Oacute;&ETH;&frac12;&sup1;&micro;&atilde;Cell&Euml;ù&Ocirc;&Uacute;&micro;&Auml;&frac14;&Iacute;&Acirc;&frac14;&micro;&Auml;&frac14;&Iacute;&Acirc;&frac14;&ordm;&Aring;}
        tag : integer; {×&icirc;&frac12;ü&frac12;&oslash;&Egrave;&euml;&cedil;&Atilde;Cell&ordm;ó&Ecirc;&Ccedil;·&ntilde;&micro;&macr;&sup3;&ouml;&Aacute;&Euml;&Iuml;&Acirc;&Agrave;&shy;&Aacute;&ETH;±í}
        r : TRect; {&Atilde;&raquo;&Oacute;&ETH;&Ecirc;&sup1;&Oacute;&Atilde;}
      end;
      

  6.   


      CurCell : TCurCell; {&frac14;&Ccedil;&Acirc;&frac14;&micro;±&Ccedil;°&Oacute;&ETH;&frac12;&sup1;&micro;&atilde;&micro;&Auml;Cell}