Solved

is there a working vb.net way to resize last column of listview to fill remainder of listview

Posted on 2004-09-15
3
438 Views
Last Modified: 2008-01-09
hi, is there a working vb.net way to resize last column of listview to fill remainder of listview that anyone knows of?
i've tried
http://www.devx.com/vb2themax/Tip/18746
Private Sub ListView1_Resize(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles ListView1.Resize
    ListView1.BeginUpdate()
    ListViewHeader2.Width = ListView1.Width - ListViewHeader2.Width - 27
    ListView1.EndUpdate()
End Sub

the problem comes that when there are more items  in the listview than those that are visible,
then because vertical scrollbar is added, a horizontal scrollbar is added as well, thus the value of 27 doesnt work

the autoresize trick (www.codeproject.com/cs/miscctrl/AutoResize.asp)
wont work either because it's in C and it uses send keys


this is prob the best i've seen but its in c# , could anyone possible help me do this in vb?
http://www.codeproject.com/cs/miscctrl/listviewautosize.asp


The Solution
To implement the the auto-size of the last column, subclass the ListView control, and override the WndProc method.

protected override void WndProc( ref Message message )
{
    const int WM_PAINT = 0xf ;

    // if the control is in details view mode and columns
    // have been added, then intercept the WM_PAINT message
    // and reset the last column width to fill the list view
    switch ( message.Msg )
    {
    case WM_PAINT:
        if ( this.View == View.Details && this.Columns.Count > 0 )
            this.Columns[this.Columns.Count - 1].Width = -2 ;
        break ;
    }

    // pass messages on to the base control for processing
    base.WndProc( ref message ) ;
}


thanks!


0
Comment
Question by:jxharding
  • 3
3 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12063628
Hi JXharding,

Public Class mylistview
    Inherits ListView

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_PAINT As Integer = 15
        Select Case m.Msg
            Case wm_paint
                If Me.View = View.Details Then
                    Me.Columns(Me.Columns.Count - 1).Width = -2
                    Exit Sub
                End If
        End Select
        MyBase.WndProc(m)
    End Sub
End Class
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12063656
maybe this is better

Const WM_PAINT As Integer = &HF
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
ID: 12063675
sorry forgot something (I never got the hang of thinking and typing at the same time)

Public Class mylistview
    Inherits ListView

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_PAINT As Integer = &HF
        Select Case m.Msg
            Case WM_PAINT
                If Me.View = View.Details And Me.Columns.Count > 0 Then
                    Me.Columns(Me.Columns.Count - 1).Width = -2
                    Exit Sub
                End If
        End Select
        MyBase.WndProc(m)
    End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now