본문 바로가기

프로그래밍/Delphi

TcxGrid에서 Popup메뉴 열리기 전에 클릭된 컬럼 및 종류 알아내기

TcxGrid에서 오른쪽 마우스 클릭시 설정된 팝업메뉴 오픈 전에 클릭된 컬럼의 종류(헤더, 본문, 풋터) 및 클릭된 컬럼 인덱스를 알아내는 방법

procedure TForm1.cxGridPopupMenu1Popup(ASenderMenu: TComponent;
  AHitTest: TcxCustomGridHitTest; X, Y: Integer; var AllowPopup: Boolean);
var
  AColumnIndex: integer;
begin
  // only allow column popup when this column is hit
  AColumnIndex := cxGrid1TableView1Column4.Index;
  // Cell was hit
  if AHitTest is TcxGridRecordCellHitTest then
    AllowPopup := TcxGridRecordCellHitTest(AHitTest).Item.Index = AColumnIndex
  else if AHitTest is TcxGridColumnHeaderHitTest then
    AllowPopup := TcxGridColumnHeaderHitTest(AHitTest).Column.Index = AColumnIndex
  else if AHitTest is TcxGridFooterCellHitTest then
    AllowPopup := TcxGridFooterCellHitTest(AHitTest).Column.Index = AColumnIndex;
end;