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

Resizing the columns in a listview

34 views
Skip to first unread message

Lazarus2000

unread,
Jul 1, 1999, 3:00:00 AM7/1/99
to
Is it just me, or are the MinWidth and MaxWidth properties of TListView
columns absolutely useless? Try this:

1. Create a new form
2. Place a TListView on it
3. Create 2 columns in it
4. Set ther MaxWidth and MinWidth values to something meaningful
5. Run the program
6. Resize the columns

Notice how they resize with reckless abandon, paying no need to the MaxWidth
or MinWidth.

Anyone else notice this? Any known discussions around this issue? Is this
(*gasp*) a BUG??

--
----------------------------------------------------------------
"Whip it, whip it GOOD."

Damon Chandler

unread,
Jul 1, 1999, 3:00:00 AM7/1/99
to
Hi Lazarus,

> Is it just me, or are the MinWidth and MaxWidth properties of TListView
> columns absolutely useless? Try this:

I don't have those properties in my version, but if it's broke, you can fix it
yourself by subclassing the ListView (or deriving a new component from TListView
and overring the WndProc() method). Look for the HD_NOTIFY message which is
sent in the form of a WM_NOTIFY message. Within the HD_NOTIFY message, test for
the HDN_ITEMCHANGING code of the NMHDR member of the message...


//in header...
Controls::TWndMethod OldListViewWP;
void __fastcall NewListViewWP(TMessage &Msg);

//in source...
const int MinWidth = 20;
const int MaxWidth = 100;

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldListViewWP = ListView1->WindowProc;
ListView1->WindowProc = NewListViewWP;
}

void __fastcall TForm1::NewListViewWP(TMessage &Msg)
{
if (Msg.Msg == WM_NOTIFY)
{
HD_NOTIFY *phdn = (HD_NOTIFY *)Msg.LParam;
if (phdn->hdr.code == HDN_ITEMCHANGING)
{
if (phdn->pitem->cxy < MinWidth ||
phdn->pitem->cxy > MaxWidth)
{
Msg.Result = true;
return;
}
}
}
OldListViewWP(Msg);
}


void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
ListView1->WindowProc = OldListViewWP;
}

Alternatively, you can use the the HDN_TRACK notification to prevent the
resizing to a limit during actual resizing...

void __fastcall TForm1::NewListViewWP(TMessage &Msg)
{
if (Msg.Msg == WM_NOTIFY)
{
HD_NOTIFY *phdn = (HD_NOTIFY *)Msg.LParam;
if (phdn->hdr.code == HDN_TRACK)
{
if (phdn->pitem->cxy > MaxWidth)
phdn->pitem->cxy = MaxWidth;
if (phdn->pitem->cxy < MinWidth)
phdn->pitem->cxy = MinWidth;
}
}
OldListViewWP(Msg);
}


Good luck.

--------------------------------------
Damon Chandler

http://bcbcaq.freeservers.com
Answers to <Commonly Asked Questions>

0 new messages