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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM