Re: ListView control header events? by aualias
aualias
Mon Nov 08 14:10:38 CST 2004
Jeffrey,
Thanks for the sample. I never actually checked for resizing - I just saw
stuff on the Internet that indicated that no header messages are sent and
assumed that it was true. What I looked at, and what I am most interested
in, are the messages sent when you reorder the column headers.
I did look for the reorder messages and found nothing that matched values in
commctrl.h. ( I did find some messages that came between the gaps in
sequential values in commctrl.h, but I do not know what to do with them. )
Alfredo
""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:NuZj75TxEHA.2544@cpmsftngxa10.phx.gbl...
> Hi Alfredo,
>
> When the user drags the certain column header, the column header will send
> a WM_NOTIFY message with HDN_BEGINTRACKW(A) code to the ListView, and when
> the draging is over, a WM_NOTIFY message with HDN_ENDTRACKW(A) code will
> also be sent to ListView control.
>
> So, we can inherit from the ListView class, override WndProc method, then
> intercept the WM_NOTIFY message with these 2 notify code to get the column
> width draging event. Sample code lists below:
>
> private const uint WM_NOTIFY=0x004E;
> private const uint HDN_BEGINTRACKA = 0xFFFFFECE;
> private const uint HDN_BEGINTRACKW = 0xFFFFFEBA;
> private const uint HDN_ENDTRACKA = 0xFFFFFECD;
> private const uint HDN_ENDTRACKW = 0xFFFFFEB9;
>
> [StructLayout(LayoutKind.Sequential)]
> public struct NMHDR
> {
> public uint hwndFrom;
> public uint idfrom;
> public uint code;
> }
>
> protected override void WndProc(ref Message m)
> {
> if(m.Msg==WM_NOTIFY)
> {
> NMHDR nm=(NMHDR)m.GetLParam(typeof(NMHDR));
> if(nm.code==HDN_BEGINTRACKA||nm.code ==HDN_BEGINTRACKW)
> {
> //the draging begins, just save the column width setting, call
> savecolumnsetting() method I listed below
> }
> else if(nm.code == HDN_ENDTRACKA ||nm.code == HDN_ENDTRACKW)
> {
> //draging is over
> }
> }
> base.WndProc (ref m);
> }
> To record and restore the column width setting, we may write 2 methods for
> our own, like this:
> ArrayList al=new ArrayList();
> public void savecolumnsetting()
> {
> al.Clear();
> for(int i=0;i<this.Columns.Count;i++)
> {
> al.Add(this.Columns[i].Width);
> }
> }
>
> public void restorecolumnsetting()
> {
> for(int i=0;i<this.Columns.Count;i++)
> {
> this.Columns[i].Width=(int)al[i];
> }
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Usage:
> Because whenever we drag the column header, its original width setting is
> saved in arraylist, we can use a button to invoke restorecolumnsetting()
> method, then when we clicked the button, the listview headers will restore
> to its original width.
>
> It works well on my side, I will attach the sample project in this reply
> for your information.
> ============================================================
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.