Board index » delphi » Which subitem of a Listview's Listitem was clicked?

Which subitem of a Listview's Listitem was clicked?

I have a listview that is displayed using the vsReport view style...it
contains a number of columns, and subsequently, the listitems have
corresponding subitems.  I want to give the user the ability to edit the
text in any of the subitems by just clicking on the subitem.  How does one
do this?  I can't seem to figure out a straight forward way to capture the
subitem index when a listitem is clicked.  Any help will be appreciated...

Thanks in advance,

Tom

 

Re:Which subitem of a Listview's Listitem was clicked?


Hi Tom

As far as I'm concerned there are noway of editing just the subItem, you
have to edit the entire Item. May suppose that you assign a onDoubleClick to
your TListView and when that event is pulled then open a new form where you
offer the user to edit the contest og the clicked Item.

If interested I vould make you an complete ekample and mail it to you ...

Jens B

Quote
Tom Rafferty <traffe...@interactivesi.com> wrote in message

news:39a2e6bf$1_2@dnews...
Quote
> I have a listview that is displayed using the vsReport view style...it
> contains a number of columns, and subsequently, the listitems have
> corresponding subitems.  I want to give the user the ability to edit the
> text in any of the subitems by just clicking on the subitem.  How does one
> do this?  I can't seem to figure out a straight forward way to capture the
> subitem index when a listitem is clicked.  Any help will be appreciated...

> Thanks in advance,

> Tom

Re:Which subitem of a Listview's Listitem was clicked?


Quote
"Tom Rafferty" <traffe...@interactivesi.com> wrote in message

news:39a2e6bf$1_2@dnews...

Quote
> I can't seem to figure out a straight forward way to capture the
> subitem index when a listitem is clicked.  Any help will be appreciated...

The following is copied and pasted from 2 different units in an old D3
project. The version of ListView_SubItemHitTest in D3 didnt allow for
subitems to be "hit-tested" I think because it wasn't available in the
version of ComCtl32.DLL at the time.

uses
  CommCtrl, ComCtrls;

type
  // Updated version of TLVHitTestInfo (has also been updated in D5)
  PLVHitTestInfoNew = ^TLVHitTestInfoNew;
  TLVHitTestInfoNew = record
                        Pt : TPoint;
                        Flags : integer;
                        iItem : integer;
                        iSubItem : integer;
                      end;

// Updated version of CommCtrl function
function ListView_SubItemHitTest(hwndLV: HWND; var lvhti:
TLVHitTestInfoNew ): Integer;
begin
  Result := SendMessage(hwndLV, LVM_SUBITEMHITTEST, 0, Longint(@lvhti));
end;

function ListViewSubItemHitTest(Handle : HWND; X: integer; Y: Integer) :
integer;
var
  HitTest: TLVHitTestInfoNew;
begin
  HitTest.pt.X := X;
  HitTest.pt.Y := Y;
  // Calls ListView_SubItemHitTest from *this* unit, not from CommCtrl.pas
  ListView_SubItemHitTest(Handle, HitTest);
  Result := HitTest.iSubItem;
end;

procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
  Item: TListItem;
  iSubItem: integer;
begin
  Item := ListView1.GetItemAt(X, Y);
  if Assigned(Item) then
    begin
    iSubItem := ListViewSubItemHitTest(ListView1.Handle, X, Y);
    // etc
    end;
end;

--
Dave Nottage

Other Threads