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."
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>