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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extracting last characters in a substring 5 27
Get hold of longitude and latitude in iframe string 11 46
Error handling in asp.net site 5 28
ASP/VB email question 4 35
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

777 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