1. 程式人生 > >Delphi DBGrid雙擊事件、單元格操作

Delphi DBGrid雙擊事件、單元格操作

1、得到當前格子中的內容:
DBGrid1.Fields[DBGrid1.SelectedIndex].DisplayText;
把DBGrid1.SelectedIndex改為你所希望引用的欄位就可以了,如第3個欄位。

DBGrid1.Fields[3].DisplayText;

2、雙擊單元格觸發不同事件

procedure TMainFrm.DBGrid1DblClick(sender:TObject);

begin

if dbgrid1.fields[dbgrid1.selectedIndex].FiledName='GNO' then begin // dbgrid1.selectedIndex ---選中單元格列

//響應事件

end;

if dbgrid1.fields[dbgrid1.selectedIndex].FiledName='PSNNAME' then begin

//響應事件
end;

if dbgrid1.fields[dbgrid1.selectedIndex].FiledName='RCSJ' then begin

//響應事件

end;

end;