Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ListView column freeze

11 views
Skip to first unread message

Stephane Hebert

unread,
Sep 21, 2001, 3:03:46 PM9/21/01
to
Hi folks,

Anybody knows how to prevent a ListView column from being dragged/resized ?

Thanks


--
============================
Stéphane Hébert
ste...@audiocontrole.com
============================


Geoff Schaller

unread,
Sep 23, 2001, 3:00:23 AM9/23/01
to
Yes, buy bBrowser and use this instead.
Its even a WED option.

However, I am sure that if you subclass the WndProc of the Listview you
could trap the relevant event and repel it. You'd be looking for a mouse
down type of event whose coordinates translated to the caption area. I don't
know the answer - I just use bBrowser now.

Geoff


"Stephane Hebert" <sgtp...@bootcamp.com> wrote in message
news:c9Mq7.24164$386.3...@news20.bellglobal.com...

Paolo Cherubini

unread,
Sep 23, 2001, 9:58:29 AM9/23/01
to
Hello Stephane,

It seems you have to trap notifications from the header control; you
are going to suffer <g>.

Take a look at:
http://codeguru.earthweb.com/listview/no_col_resize.shtml
and
http://codeguru.earthweb.com/listview/no_col_resize2.shtml

Ciao
Paolo


"Stephane Hebert" <sgtp...@bootcamp.com> ha scritto nel messaggio
news:c9Mq7.24164$386.3...@news20.bellglobal.com...

Stephane Hebert

unread,
Sep 23, 2001, 2:58:53 PM9/23/01
to
Thanks Paolo, looks like that's going to do it.


--
Stephane Hebert
=========================
stephhebert@yourpants~videotron.ca
Remove yourpants~ to reply
=========================
"Paolo Cherubini" <pa...@ats.it> wrote in message
news:9okp5j$frl$1...@nreadb.inwind.it...

Marc Forsyth

unread,
Sep 23, 2001, 11:04:07 PM9/23/01
to
Stephan,

You'll need to attack the LV's header control.
Check some recent messages about header controls that I have been involved in.
The following is for my browser's header control but will still apply.

method SetHeaderOwnerDraw() as void pascal class FpDataBrowser
// Convert all Header items to ownerdraw
local oHeader as FpHeaderControl
~"ONLYEARLY+"
oHeader := self:oHdr
oHeader:GoOwnerDraw()
return
~"ONLYEARLY-"
//
//
method DisableColResize() as void pascal class FpDataBrowser
// Disable Resizing of columns via Header item divider dragging
local oHeader as FpHeaderControl
~"ONLYEARLY+"
self:lEnableColResize := false
oHeader := self:oHdr
oHeader:DisableItemResize()
return
~"ONLYEARLY-"
//
//
**********************
class FpHeaderControl inherit cHeaderControl
//
~"ONLYEARLY+"
protect nCurrentCol as longint
protect lAllowItemResize as logic

declare access ColumnNo
declare assign ColumnNo
declare method GoOwnerDraw
declare method DisableItemResize
~"ONLYEARLY-"
//
//
access ColumnNo as longint pascal class FpHeaderControl
//
~"ONLYEARLY+"
return self:nCurrentCol
~"ONLYEARLY-"
//
//
assign ColumnNo(nCol as longint) as longint pascal class FpHeaderControl
//
~"ONLYEARLY+"
self:nCurrentCol := nCol
return nCol
~"ONLYEARLY-"
//
//
method Init(oParent,xID,oOrigin,oSize,cClassName,nStyle,nExtStyle) class FpHeaderControl
// Initialize and subclass

//default nStyle to _or(WS_CHILD,HDS_BUTTONS,HDS_HORZ,)

super:Init(oParent,xID,oOrigin,oSize,cClassName,nStyle,nExtStyle)
self:Subclass()

self:lAllowItemResize := true
self:nCurrentCol := -1

return self
//
//
method _ProcessNotifyMsg(oEvent as cControlNotifyEvent) as longint pascal class FpHeaderControl
//
~"ONLYEARLY+"
if oEvent:NotifyCode == HDN_BEGINTRACK
if .not. self:lAllowItemResize
return 1L // Don't do it
endif
endif
return super:_ProcessNotifyMsg(oEvent)

~"ONLYEARLY-"
//
//
method OnSetCursor(oEvent as cEvent) as longint pascal class FpHeaderControl
// Prevent Cursor change if .not. lAllowItemResize
~"ONLYEARLY+"
// Intercept Divider Drag
if .not. self:lAllowItemResize
return 1
endif
return super:OnSetCursor(oEvent)
~"ONLYEARLY-"
//
//
method OnMouseButtonDown(oEvent as cMouseEvent) as longint pascal class FpHeaderControl
// Prevent sensitivity to Divider Click when .not. lAllowItemResize
local nHitTestCodes as dword
local nItemIndex as longint
local oBB as cBoundingBox
local nX as longint
local nPos as dword
~"ONLYEARLY+"
if .not. self:lAllowItemResize

nItemIndex := self:HitTest( oEvent:Position, @nHitTestCodes )

if _and(nHitTestCodes, HHT_ONDIVIDER) == HHT_ONDIVIDER

// Is the divider click inside THIS item?
oBB := self:GetItemBoundingBox(nItemIndex)

if .not. oBB:PointInside(oEvent:Position)

// Must be in the NEXT!
oBB := self:GetItemBoundingBox(nItemIndex + 1)
endif

// Send a dummy click to the selected item
// Make sure the position is well centered within the item
nX := oBB:Left + ( (oBB:Right - oBB:Left) / 2 )
nPos := MakeLong(word(_cast, nX), word(_cast, oEvent:Position:Y))

self:SendMessage( WM_LBUTTONDOWN, MK_LBUTTON, longint(_cast, nPos) )
return 0
endif
endif
return super:OnMouseButtonDown(oEvent)
~"ONLYEARLY-"
//
//
method DisableItemResize() as void pascal class FpHeaderControl
// Disable Resizing of items via divider dragging
~"ONLYEARLY+"
self:lAllowItemResize := false
return
~"ONLYEARLY-"
//
//
method GoOwnerDraw() as void pascal class FpHeaderControl
// Convert all Header items to ownerdraw
local nItemIndex as longint
local oHdrItem as cHeaderControlItem
~"ONLYEARLY+"
for nItemIndex := 0 upto (self:ItemCount - 1)
oHdrItem := self:GetItem(nItemIndex)
oHdrItem:Alignment := HDF_OWNERDRAW
self:SetItemAttributes( oHdrItem, nItemIndex)
next

return
~"ONLYEARLY-"
//
//
method OnOwnerDraw_DrawItem(oEvent as cEvent) as longint pascal class FpHeaderControl
// custom draw for multi-line Header items
local sDI as _WINDRAWITEMSTRUCT
local oHdrItem as cHeaderControlItem
local pText as psz
local sDrawRect is _WINRECT
~"ONLYEARLY+"
// Get the DrawItem structure
sDI := ptr(_cast, oEvent:lParam)

// Get the individual Header Item info.
oHdrItem := self:GetItem( longint(_cast, sDi.ItemId) )

// Drawing of the "button" is done by the headercontrol only - I cannot override
// Build the Header button
// DrawFrameControl( sDI.hDC, @sDI.rcItem, DFC_BUTTON, DFCS_BUTTONPUSH)

// Draw the header text
pText := StringAlloc( oHdrItem:Caption )

// Adjust the rectangle so we start text a bit further down
CopyRect(@sDrawRect, @sDi.rcItem)
sDrawRect.Top += 1

DrawText(sDI.hDC, pText, longint(_cast, sLen(oHdrItem:Caption)), @sDrawRect, DT_CENTER)

MemFree(pText)

return Longint(_cast, TRUE)
~"ONLYEARLY-"
//
//

-Marc-

Paolo Cherubini

unread,
Sep 24, 2001, 12:19:46 PM9/24/01
to
Hello,

Try the following code.
It simply restore the original width of an item in the header of a
listview after a drag.

Ciao Paolo
------------------------------
METHOD Dispatch(oE) CLASS MyWindow

STATIC lStart:=FALSE AS LOGIC , ;
nItem :=0 AS INT , ;
nLung :=0 AS INT

LOCAL sNotifica AS _winHD_NOTIFY, ;
sColonna IS _WINHDITEM

&& Select the notify messages
IF oE:Message=WM_NOTIFY

&& Fill the structure with the notify informations
sNotifica:=PTR(_CAST, oE:lParam)

&& The user is dragging a divider in the header control
IF sNotifica.hdr._code=HDN_TRACK

IF !lStart

&& Do remeber next call the dragging already started
lStart:=TRUE

&& Ask the header control about the width of the
&& current item at this moment
sColonna.Mask:=HDI_WIDTH

SendMessage(sNotifica.hdr.hwndFrom , ;
HDM_GETITEM , ;
DWORD(_CAST, sNotifica.iItem), ;
LONGINT(_CAST, @sColonna))

&& Store the item width
nLung:=sColonna.cxy

&& Store the item number
nItem:=sNotifica.iItem

ENDIF

// The item changed
ELSEIF sNotifica.hdr._code==HDN_ITEMCHANGED

&& lStart true in here means the user finished doing the drag
IF lStart

SUPER:Dispatch(oE)

lStart:=FALSE

&& Restore the original width of the item
sColonna.Mask := HDI_WIDTH
sColonna.cxy := nLung

SendMessage(sNotifica.hdr.hwndFrom, ;
HDM_SETITEM , ;
DWORD(_CAST, nItem) , ;
LONGINT(_CAST, @sColonna))

RETURN 0L

ENDIF

ENDIF

ENDIF

RETURN SUPER:Dispatch(oE)

STRUCT _WINHDITEM
MEMBER mask AS DWORD
MEMBER cxy AS INT
MEMBER pszText AS PSZ
MEMBER hbm AS PTR
MEMBER cchTextMax AS INT
MEMBER fmt AS INT
MEMBER lParam AS LONG
MEMBER iImage AS INT
MEMBER iOrder AS INT


"Stephane Hebert" <stephhebert@yourpants~videotron.ca> ha scritto nel
messaggio news:ijqr7.4230$Kj4.3...@wagner.videotron.net...

Stephane Hebert

unread,
Sep 24, 2001, 8:46:06 AM9/24/01
to
Marc,

Thanks.


--
Stephane Hebert
=========================
stephhebert@yourpants~videotron.ca
Remove yourpants~ to reply
=========================

"Marc Forsyth" <Ma...@Fpss.Net> wrote in message
news:3BAEA2A...@Fpss.Net...

Marc Forsyth

unread,
Sep 24, 2001, 4:46:04 PM9/24/01
to
Stephan,

BTW. That code was also intended to allow the headercontrol text
to be multi-line by going owner-draw on all the header items.

-Marc-

Stephane Hebert

unread,
Sep 25, 2001, 3:34:56 PM9/25/01
to
Paolo,

Ok, that hit the spot.

Thanks !


--
============================
Stéphane Hébert
ste...@audiocontrole.com
============================

"Paolo Cherubini" <pa...@ats.it> a écrit dans le message news:
9onm0v$ee5$1...@nreada.inwind.it...

0 new messages