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
436 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
Comment Utility
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
Comment Utility
maybe this is better

Const WM_PAINT As Integer = &HF
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

12 Experts available now in Live!

Get 1:1 Help Now