본문 바로가기
Programming/*Delphi

ListView SubItem 을 Combobox를 이용하여 수정하기.

by Aur0ra 2020. 8. 6.

ListView를 클릭하여 SubItem을 ComboBox를 통해 수정하는 동작을 구현 했습니다.

 

ListView 의 속성은

 

ReadOnly - > True

RowSelect -> True

ViewStyle -> vsReport

 

으로 주었습니다.

 

<Code>

  idx : integer;
implementation

{$R *.dfm}

procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
var
 r : TRect;
begin
 if Selected = True then
 begin
   idx := Item.Index;

   try
     GetWindowRect(Item.Handle,r);

     ComboBox1.Text := Item.SubItems[0];
     //원하는 SubItem 인덱스를 넣어주시면됩니다.
     ComboBox1.Visible := True;
     ComboBox1.Width := ListView1.Columns.Items[1].Width;
     //원하는 SubItem을 가지고있는 칼럼의 인덱스를 넣어주시면됩니다.
     ComboBox1.Height := r.Bottom - r.Top;
     ComboBox1.Left := Item.Left + ListView1.Left + ListView1.Columns.Items[0].Width;
     //원하는 SubItem을 가지고 있는 칼럼이 아닌 그 전 인덱스의 칼럼들의 Width를 연산해줍니다.
     ComboBox1.Top  := Item.Top  + ListView1.Top;

   finally

   end;

 end
 else
 begin
   idx := -1;
   ComboBox1.Visible := False;
 end;


end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  if idx > -1 then
  begin
    ListView1.Items[idx].SubItems[0] := ComboBox1.Text;
    //원하는 SubItem의 인덱스를 넣어주시면됩니다.
  end;

end;

 

<동작>

 

 

댓글