Announcement

Collapse
No announcement yet.

Spalten bei der Listview zur Laufzeit ausblenden

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spalten bei der Listview zur Laufzeit ausblenden

    Wie kann man zur Laufzeit Spalten(Columns) einer Listview ausblenden und dann nach bedarf wieder einblenden.
    Hab die ganze Delphi Hilfe abgesucht, aber nichts brauchbares gefunden.

  • #2
    Hallo Bernd,<br>probier doch mal ListView1.Columns[iCnt].Width:=0;<br>:-) Jens schuman

    Comment


    • #3
      Den Trick habe ich schon probiert, aber ist nicht ganz so sauber, da man die Columns wieder auseinanderziehen kann :O

      Comment


      • #4
        Hallo Bernd,
        hier ist eine Beispiel zu erste Column in einer Listview ausblenden und dann nach bedarf wieder einblenden.

        unit MyListview;

        interface

        uses
        Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,Commctrl,Comctrls;

        type
        TMyListView = class(TListview)
        private
        FUpdatingColumnOrder: Boolean;
        FHeaderHandle: HWND;
        FHeaderInstance: Pointer;
        FDefHeaderProc: Pointer;
        procedure WMNCCalcSize(Var msg : TMessage); message WM_NCCALCSIZE;
        procedure WMNotify(var Message: TWMNotify); message WM_NOTIFY;
        procedure WMParentNotify(var Message: TWMParentNotify); message WM_PARENTNOTIFY;
        end;

        type
        TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        private
        lListView : TMyListview;
        { Private declarations }
        public
        { Public declarations }
        end;

        var
        Form1: TForm1;

        implementation

        {$R *.DFM}

        procedure TMyListView.WMNCCalcSize(Var msg : TMessage);
        var Style : Integer;
        begin
        Style := getWindowLong(Handle, GWL_STYLE);
        if (Style and WS_HSCROLL) <> 0
        then SetWindowLong(Handle, GWL_STYLE,Style and not WS_HSCROLL);
        inherited;
        end; //TMyListView.WMNCCalcSize

        procedure TMyListView.WMParentNotify(var Message: TWMParentNotify);
        begin
        with Message do
        if (Event = WM_CREATE) and (FHeaderHandle = 0) then
        begin
        FHeaderHandle := ChildWnd;
        FDefHeaderProc := Pointer(GetWindowLong(FHeaderHandle, GWL_WNDPROC));
        SetWindowLong(FHeaderHandle, GWL_WNDPROC, LongInt(FHeaderInstance));
        end;
        inherited;
        end; //TMyListView.WMParentNotify

        procedure TMyListView.WMNotify(var Message: TWMNotify);
        var
        P: TPoint;
        hChildWnd: HWND;
        WndClass: string;
        hdhti: THDHitTestInfo;
        begin
        if (Message.NMHdr^.hWndFrom = FHeaderHandle) then
        with Message.NMHdr^ do begin
        inherited;
        case code of
        HDN_BEGINTRACKA : begin
        with PHDNotify(Pointer(Message.NMHdr))^, PItem^ do begin
        if (Item = 0) then begin
        Column[0].Width := 0;
        Message.Result := 1;
        end;
        end;
        end;
        HDN_BEGINTRACKW : begin
        with PHDNotify(Pointer(Message.NMHdr))^, PItem^ do begin
        if (Item = 0) then begin
        Column[0].Width := 0;
        Message.Result := 1;
        end;
        end;
        end;
        HDN_ENDDRAG:
        FUpdatingColumnOrder := True;
        HDN_DIVIDERDBLCLICK:
        with PHDNotify(Pointer(Message.NMHdr))^ do begin
        if IsCustomDrawn(dtControl, cdPrePaint) then Invalidate;
        end;
        NM_RCLICK: begin
        P := Point(LoWord(GetMessagePos), HiWord(GetMessagePos));
        hChildWnd := ChildWindowFromPoint(Handle, ScreenToClient(P));
        if (hChildWnd <> 0) and (hChildWnd <> Handle) then begin
        SetLength(WndClass, 80);
        SetLength(WndClass, GetClassName(hChildWnd, PChar(WndClass), Length(WndClass)));
        if WndClass = 'SysHeader32' then begin
        hdhti.Point := ScreenToClient(P);
        if SendMessage(hChildWnd, HDM_HITTEST, 1, Longint(@hdhti)) >= 0
        then ColRightClick(Column[hdhti.Item], hdhti.Point);
        end;
        end;
        end;
        end;
        end;
        end; // TMyListView.WMNotify

        procedure TForm1.FormCreate(Sender: TObject);
        var
        lColumneu : TListColumn;
        begin
        lListview := TMyListview.Create(Self);
        lListview.ParentWindow := Handle;
        lListview.ViewStyle := vsReport;
        With lListview do begin
        Left := 0;
        Top := 0;
        Width:= 400;
        Height := 400;
        lColumneu := Columns.Add;
        lColumneu.Caption := 'Test1';
        lColumneu.Width := 200;
        lColumneu := Columns.Add;
        lColumneu.Caption := 'test2';
        lColumneu.Width := 200;
        Visible := TRUE;
        end;
        end;

        end.
        my E-Mail adresse : thietquy@hotmail.

        Comment

        Working...
        X