请问各位大侠,如何才能控制stringgrid,dbgrid 各cell的读写性,有没有一种方法控制,一个DBgrid的前几列为只读,而后几列为可写(在视图模式下),或都控制stringgrid的前几列为只读,而后几列为可写呢?
大家都知道sql可以实现如:select 姓名,数学+语文+外英 as 总分 from ...这样的功能,能不能让视图的某列的值全部赋值为一个字符串常量显示呢?

解决方案 »

  1.   

    第一个问题:
    if StringGrid2.Row>0 then
        if StringGrid2.Col=1 then
          begin
            StringGrid2.Options:=StringGrid2.Options+[goediting]
          end
        else
        begin
          StringGrid2.Options:=StringGrid2.Options -[goediting];
        end;
      

  2.   

    第二个问题  假设字符常量为string
      select 姓名,数学+语文+外英 as 总分 ‘string' as fieldname from ...
      

  3.   

    有很多方法都可以
    比如在dbgrid onkeypress事件加入if 条件
    判断字段是否为可改字段,将其设为可改
    退出事件时再反readonly 设为 true;
      

  4.   

    DBGrid1.Column[0].Readonly:=True;   //第一列只读了