§ ListViewWndProc
A way to handle some messages for TListView without subclassing a new component. In particular, this provides the EditCancel event that Delphi does not provide, and allows hiding the horizontal scrollbar which can be a problem in some circumstances.
type
TForm1 = class(TForm)
private
{ Private declarations }
...
fListViewWndProc: TWndMethod;
procedure ListViewWndProc(var msg: TMessage);
...
end;
procedure TForm1.FormCreate(Sender: TObject); begin ... fListViewWndProc := ListView1.WindowProc; ListView1.WindowProc := ListViewWndProc; ... end;
procedure TForm1.ListViewWndProc(var msg: TMessage);
var
oldStyle, newStyle: integer;
begin
//get listview edit cancel event
//https://groups.google.com/forum/#!topic/borland.public.delphi.vcl.components.using/4Wp-bHioono YAY Brad Stowers!
if msg.Msg = CN_NOTIFY then
begin
if TWMNotify(msg).NMHdr^.code = LVN_ENDLABELEDIT then
with PLVDispInfo(Pointer(TWMNotify(msg).NMHdr))^ do
if (item.pszText = nil) and (item.iItem <> -1) then
ListViewEditCanceled(item.iItem); //edit canceled. iItem = index
end;
//hide horizontal scrollbar
//http://codeverge.com/embarcadero.delphi.vcl.using/hiding-scrollbars-for-dbctrlgrid/1067707 Peter Below
if msg.Msg = WM_NCCALCSIZE then
begin
oldStyle := GetWindowLong(ListView1.Handle, GWL_STYLE);
if fHideHScroll then
newStyle := oldStyle and not WS_HSCROLL
else
newStyle := oldStyle or WS_HSCROLL;
if newStyle <> oldStyle then
SetWindowLong(ListView1.Handle, GWL_STYLE, newStyle);
end;
fListViewWndProc(msg);
end; //ListViewWndProc
last edited on March 2nd, 2016 at 1:39 PM
Categories
Comments
- Walid on "Adventures with Ubuntu 9.10 on G4 Yikes!" - I am in the same process as you. Although I still dual-boot to Windows for my ganimg leisure. My first contact with Ubuntu was way…
- Slashback on "Simpler adding & removing element classnames" - Actually, the addClassName function does what you want, pretty much the same way you suggest.
- angie on "Simpler adding & removing element classnames" - And what if I want to add a class, but keeping the csseals the element already has?I mean, I have an element with a class, let's name…
- backlinks on "Adjust iframe height to contents" - Definitely helped me.
- Slashback on "Simpler validate form fields are filled in (no additional class names)" - You are welcome!