0

How can I have a single column resize with the form so that the ListView columns continue to fill the whole form?

2
  • Is your qustion about ListBox with MultiColumn set to true? Commented May 30, 2010 at 1:38
  • No, it's the "ListView" control. Commented May 30, 2010 at 1:40

1 Answer 1

1

Yes, implement the listview's Resize event handler and calculate the space left for the column. For example:

Private Sub ListView1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.Resize
    Dim resizeColumn As Integer = 1
    Dim w As Integer = 0
    For column As Integer = 0 To ListView1.Columns.Count - 1
        if column <> resizeColumn then w += ListView1.Columns(column).Width
    Next
    w = ListView1.ClientSize.Width - w - 1 - SystemInformation.VerticalScrollBarWidth
    If w > 0 Then ListView1.Columns(resizeColumn).Width = w
End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    ListView1_Resize(Me, EventArgs.Empty)
    MyBase.OnLoad(e)
End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

That worked well, however how can I select which column to resize?
Herpderp. Which part? I tried changing almost all the variables and got no good results.
@Ben: code updated. Change "resizeColumn" to the column you want to get resized.
Thanks a lot Hans, appreciate it!
@Ben, this wasn't helpful? Sounds like it was, a "this was helpful" upvote is appropriate perhaps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.