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
450 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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