Autor Beitrag
Gerhard_S
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98



BeitragVerfasst: So 30.09.12 01:33 
Hallo,
um die SubItems eines ListView editierbar zu machen, habe ich dank Google eine Anleitung gefunden, wie es mit C# geht:
codezentrale.bplaced.net/dcz/?p=879
Ich will versuchen, das nach Delphi zu übertragen, komme aber schon an dieser Stelle nicht weiter:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
// Event des ListViews
// zum Merken des zuletzt angeklickten ListViewItems
    private void ListView1_MouseUp(object sender, MouseEventArgs e)
    {
        ListViewHitTestInfo htInfo = ListView1.HitTest(e.X, e.Y);
        if (htInfo != null)
        {
            if (htInfo.Item != null && htInfo.SubItem != null)
            {
                _lvSubItemEdit = htInfo.SubItem;
            }
        }
    }

In Delphi kann ich nur so schreiben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var hts : THitTests; ListViewCursPos : TPoint; SelectedItem : TListItem;
begin
   hts := ListView1.GetHitTestInfoAt(ListViewCursPos.X, ListViewCursosPos.Y) ;
   if hts = [htOnLabel] then  //htOnItem bleibt ohne Ergebnis
   begin
     SelectedItem := ListView1.Selected;
     Label1.Caption := SelectedItem.Caption;
   end;
end;

Davon ausgehend könnte ich jetzt die SubItems auslesen und alle vorhandenen SubItems zum Editieren anbieten. Das ist aber nicht Sinn der Übung.
Gibt es eine Möglichkeit, die Eigenschaft htOnItem so wie in C# auszuwerten?
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: So 30.09.12 08:56 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
uses CommCtrl;
{$R *.dfm}



procedure TForm3.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  // 2012 by Thomas Wassermann
  var
   ht:TLVHitTestInfo;
begin
    ht.pt := Point(x,y);
    SendMessage(ListView1.Handle, LVM_HITTEST, 0, Longint(@ht));
    if ht.flags=1 then
        SendMessage(ListView1.Handle, LVM_SUBITEMHITTEST, 0, Longint(@ht));

   Showmessage(BoolToStr((ht.flags and LVHT_ONITEMLABEL) = LVHT_ONITEMLABEL) + #13#10 + Format('Item: %d  SubItem: %d Group: %d',[ht.iItem,ht.iSubItem,ht.iGroup]));
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 30.09.12 10:28 
Du kannst auch einfach die VirtualTreeView benutzen, dann kannst du dir das ganze sparen, weil die das schon alles unterstützt...