如题谢谢。我只找到操作单个列是否只读,但我现在需要一个列里的某些cell只读。

解决方案 »

  1.   

    可以用这OnCellClick事件动态判断实现,从这ACellViewInfo判断,如果是点击你要的Cell时,将整列只读就可以了,否则可编辑。
      

  2.   

    现在的问题是这样的,这几个需要判断的列在显示形式上采用的是CheckBox形式。我的目的是其中的某几个cell在点击以后不能改变原来的值,类似readonly效果,而其余那些值却是可以改变的。
      

  3.   

    试试enabled=.f
    ---------------------------------------------
    什么的enabled?cxGridDBTableView的?
      

  4.   

    ongetproperties里面,根据你的要求,把properties赋值为label
      

  5.   

    这个简单,tableview的onEditing事件,可以根据你的条件,符合条件的设置为:AAllow := False;即可。
      

  6.   

    如果需要条件,代码和如下类似:
        if (TableView.Controller.FocusedRecord.Values[需要判断的列] = 值) and (AItem.Index= 第几列) then
          AAllow := False
       else
           AAllow := True;
      

  7.   

    測試正解:procedure TFeeder_Alternative_F.cxGrid3DBTableView1Editing(
      Sender: TcxCustomGridTableView; AItem: TcxCustomGridTableItem;
      var AAllow: Boolean);
    begin
      inherited;
      if  AItem.ID in[0,1,2,3,4,5,6,7,9] then
      begin
        AAllow:=False;
        cxGrid3DBTableView1Column9.Properties.ReadOnly:=True;
      end;
      if AItem.ID=0 then
      begin
        if cxGrid3DBTableView1.DataController.Controller.FocusedRecord.Values[10]='0' then
        begin
          AAllow:=False;
          cxGrid3DBTableView1Column9.Properties.ReadOnly:=True;
          MessageDlg('提示:已鎖定,此筆材料不能作替代料!',mtWarning,[mbOK],0);
          Exit;
        end
      else
        begin
          if cxGrid3DBTableView1.DataController.Controller.FocusedRecord.Values[6]<>'00' then
          begin
            AAllow:=False;
            cxGrid3DBTableView1Column9.Properties.ReadOnly:=True;
            MessageDlg('提示:已鎖定,此筆材料不能作替代料!',mtWarning,[mbOK],0);
            Exit;
          end
        else
          AAllow:=True;
          cxGrid3DBTableView1Column9.Properties.ReadOnly:=False;
        end;
      end;
    end;
      

  8.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
      dxSkinsCore, dxSkinLondonLiquidSky, cxStyles, cxCustomData, cxFilter, cxData,
      cxDataStorage, cxEdit, DB, cxDBData, ADODB, cxGridLevel, cxClasses,
      cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
      cxGrid, cxExtEditRepositoryItems;type
      TForm1 = class(TForm)
        cxGrid1DBTableView1: TcxGridDBTableView;
        cxGrid1Level1: TcxGridLevel;
        cxGrid1: TcxGrid;
        Dst_1: TADODataSet;
        Dst_1Check: TBooleanField;
        Dst_1str: TStringField;
        Dst_1str2: TStringField;
        Ds_1: TDataSource;
        cxGrid1DBTableView1Check: TcxGridDBColumn;
        cxGrid1DBTableView1str: TcxGridDBColumn;
        cxGrid1DBTableView1str2: TcxGridDBColumn;
        cxEditRepository1: TcxEditRepository;
        Lbl_Porp: TcxEditRepositoryLabel;
        procedure FormCreate(Sender: TObject);
        procedure cxGrid1DBTableView1strGetProperties(
          Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
          var AProperties: TcxCustomEditProperties);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.cxGrid1DBTableView1strGetProperties(
      Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
      var AProperties: TcxCustomEditProperties);
    begin
      if ARecord.Values[0] then            //根据check字段的值判断
        AProperties := Lbl_Porp.Properties;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Dst_1.CreateDataSet;
      Dst_1.AppendRecord([False,'t1','t2']);
      Dst_1.AppendRecord([False,'x1','x2']);
      Dst_1.AppendRecord([False,'z1','z2']);
      Dst_1.AppendRecord([False,'y1','y2']);
      Dst_1.AppendRecord([False,'c1','c2']);
      Dst_1.AppendRecord([False,'a1','a2']);
      Dst_1.AppendRecord([False,'e1','e2']);
    end;end.
    窗体文件object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 216
      ClientWidth = 426
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object cxGrid1: TcxGrid
        Left = 0
        Top = 0
        Width = 426
        Height = 216
        Align = alClient
        TabOrder = 0
        ExplicitLeft = 8
        ExplicitTop = 8
        ExplicitWidth = 410
        ExplicitHeight = 200
        object cxGrid1DBTableView1: TcxGridDBTableView
          NavigatorButtons.ConfirmDelete = False
          NavigatorButtons.First.Visible = True
          NavigatorButtons.PriorPage.Visible = True
          NavigatorButtons.Prior.Visible = True
          NavigatorButtons.Next.Visible = True
          NavigatorButtons.NextPage.Visible = True
          NavigatorButtons.Last.Visible = True
          NavigatorButtons.Insert.Visible = True
          NavigatorButtons.Append.Visible = False
          NavigatorButtons.Delete.Visible = True
          NavigatorButtons.Edit.Visible = True
          NavigatorButtons.Post.Visible = True
          NavigatorButtons.Cancel.Visible = True
          NavigatorButtons.Refresh.Visible = True
          NavigatorButtons.SaveBook.Visible = True
          NavigatorButtons.GotoBook.Visible = True
          NavigatorButtons.Filter.Visible = True
          DataController.DataSource = Ds_1
          DataController.Summary.DefaultGroupSummaryItems = <>
          DataController.Summary.FooterSummaryItems = <>
          DataController.Summary.SummaryGroups = <>
          OptionsBehavior.FocusCellOnTab = True
          OptionsBehavior.GoToNextCellOnEnter = True
          OptionsBehavior.FocusCellOnCycle = True
          OptionsCustomize.ColumnFiltering = False
          OptionsCustomize.ColumnsQuickCustomization = True
          OptionsData.Deleting = False
          OptionsData.DeletingConfirmation = False
          OptionsData.Inserting = False
          OptionsView.FooterMultiSummaries = True
          OptionsView.GroupByBox = False
          object cxGrid1DBTableView1Check: TcxGridDBColumn
            DataBinding.FieldName = 'Check'
          end
          object cxGrid1DBTableView1str: TcxGridDBColumn
            DataBinding.FieldName = 'str'
            OnGetProperties = cxGrid1DBTableView1strGetProperties
          end
          object cxGrid1DBTableView1str2: TcxGridDBColumn
            DataBinding.FieldName = 'str2'
          end
        end
        object cxGrid1Level1: TcxGridLevel
          GridView = cxGrid1DBTableView1
        end
      end
      object Dst_1: TADODataSet
        Parameters = <>
        Left = 48
        Top = 40
        object Dst_1Check: TBooleanField
          FieldName = 'Check'
        end
        object Dst_1str: TStringField
          FieldName = 'str'
        end
        object Dst_1str2: TStringField
          FieldName = 'str2'
        end
      end
      object Ds_1: TDataSource
        DataSet = Dst_1
        Left = 160
        Top = 40
      end
      object cxEditRepository1: TcxEditRepository
        Left = 232
        Top = 88
        object Lbl_Porp: TcxEditRepositoryLabel
        end
      end
    end