was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

34 Visitors Online


 
...die Größenänderung von Spalten in einem ListView unterbinden?
Autor: jiyong jang
[ Tip ausdrucken ]  

Tip Bewertung (15):  
     


unit TestUnit;

interface

uses
  
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls;

type
  
TForm1 = class(TForm)
    ListView1: TListView;
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    
{ Private declarations }
    
WndMethod: TWndMethod;
    function GetIndex(aNMHdr: pNMHdr): Integer;
    procedure CheckMesg(var aMesg: TMessage);
  public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

uses
  
CommCtrl;

{$R *.dfm}

function TForm1.GetIndex(aNMHdr: pNMHdr): Integer;
var
  
hHWND: HWND;
  HdItem: THdItem;
  iIndex: Integer;
  iResult: Integer;
  iLoop: Integer;
  sCaption: string;
  sText: string;
  Buf: array [0..128] of Char;
begin
  
Result := -1;

  hHWND := aNMHdr^.hwndFrom;

  iIndex := pHDNotify(aNMHdr)^.Item;

  FillChar(HdItem, SizeOf(HdItem), 0);
  with HdItem do
  begin
    
pszText    := Buf;
    cchTextMax := SizeOf(Buf) - 1;
    Mask       := HDI_TEXT;
  end;

  Header_GetItem(hHWND, iIndex, HdItem);

  with ListView1 do
  begin
    
sCaption := Columns[iIndex].Caption;
    sText    := HdItem.pszText;
    iResult  := CompareStr(sCaption, sText);
    if iResult = 0 then
      
Result := iIndex
    else
    begin
      
iLoop := Columns.Count - 1;
      for iIndex := 0 to iLoop do
      begin
        
iResult := CompareStr(sCaption, sText);
        if iResult <> 0 then
          
Continue;

        Result := iIndex;
        break;
      end;
    end;
  end;
end;

procedure TForm1.CheckMesg(var aMesg: TMessage);
var
  
HDNotify: ^THDNotify;
  NMHdr: pNMHdr;
  iCode: Integer;
  iIndex: Integer;
begin
  case 
aMesg.Msg of
    
WM_NOTIFY:
      begin
        
HDNotify := Pointer(aMesg.lParam);

        iCode := HDNotify.Hdr.code;
        if (iCode = HDN_BEGINTRACKW) or
          
(iCode = HDN_BEGINTRACKA) then
        begin
          
NMHdr := TWMNotify(aMesg).NMHdr;
          // chekck column index
          
iIndex := GetIndex(NMHdr);
          // prevent resizing of columns if index's less than 3
          
if iIndex < 3 then
            
aMesg.Result := 1;
        end
        else
          
WndMethod(aMesg);
      end;
    else
      
WndMethod(aMesg);
  end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  
WndMethod := ListView1.WindowProc;
  ListView1.WindowProc := CheckMesg;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  
ListView1.WindowProc := WndMethod;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners