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
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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