| 发表于:2007-05-30 16:46:552楼 得分:15 |
隻能進行列鎖定 给你一个在stringgrid中设置只读列的程序代码 dbgrid应该也差不多把 procedure twork_plan.stringgrid2selectcell(sender: tobject; acol, arow: integer; var canselect: boolean); var r: trect; begin empolyee.visible:=false; num.visible:=false; with sender as tstringgrid do if trim(cells[4,arow])= ' ' then begin cells[3,arow]:= 'insert '; cells[4,arow]:= '0011 '; end; with sender as tstringgrid do if (acol = 1) or (acol = 2) and (arow > = fixedrows) then //在第二列显示一个combobox begin //取消选中模式 perform( wm_cancelmode, 0, 0 ); //确定combobox的位置 r := cellrect( acol, arow ); if acol=1 then with empolyee do begin setbounds( r.left, r.top, r.right-r.left, height ); itemindex := items.indexof( cells[ acol, arow ] ); show; bringtofront; //使得combobox称为输入的焦点 setfocus; //droppeddown := true; end; if acol=2 then with num do begin setbounds( r.left, r.top, r.right-r.left, height ); text:=cells[acol,arow]; show; bringtofront; setfocus;; //使得combobox称为输入的焦点 //droppeddown := true; end; end else if access[1]= '2 ' then begin if acol=5 then if stringgrid2.cells[1,arow]=logon_user then stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect,goediting,goalwaysshoweditor] else stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect]; if acol=6 then //if stringgrid2.cells[1,arow]=logon_user then stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect,goediting,goalwaysshoweditor]; // else // stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect]; end; //设置哪个col为只读选项 if access[1]= '1 ' then begin if (acol=5) then if stringgrid2.cells[1,arow]=logon_user then stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect,goediting,goalwaysshoweditor] else stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect]; if (acol=6) then stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect]; end; //设置哪个col为只读选项 if access[1]= '3 ' then if acol=5 then if stringgrid2.cells[1,arow]=logon_user then stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect,goediting,goalwaysshoweditor] else stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect]; if acol=6 then stringgrid2.options:=[gofixedvertline,gofixedhorzline,govertline,gohorzline,gorangeselect]; end; | | |
|