请问:在DBGRID表格中,当Mouse点击任意行列时如何读出当前行某列字段内容?我在OnColEnter事件里写,却只要在不同列切换时才触发,如果在同一列点击却没有反应。 我的想法时不管点击哪列,都能读取这一行指定列的列的显示内容。谢了!

解决方案 »

  1.   

    为什么不在OnCellClick里面做呢?
      

  2.   

    定义
      Tinfo=record
        colmn:integer;//列的序号
        content:String;//当前行列的字段内容
      end;声明:
      info:Tinfo;在CellClick中如下就OK了,以后如果用到点击取得的内容,刚直接用 info.contentprocedure TForm1.DBGrid1CellClick(Column: TColumn);
    var
       str_content:string;
    begin
         str_content:=dbgrid1.DataSource.dataSet.fieldbyname(column.FieldName).AsString;
         info.colmn:=column.ID;
         info.content:=str_content;
         ShowMessage(str_content);
         ShowMessage(inttostr(info.colmn));
    end;