How can I have a single column resize with the form so that the ListView columns continue to fill the whole form?
+1
A:
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
Hans Passant
2010-05-30 02:28:22
That worked well, however how can I select which column to resize?
Ben
2010-05-30 13:27:58
Of course, just change the code.
Hans Passant
2010-05-30 14:02:35
Herpderp.Which part? I tried changing almost all the variables and got no good results.
Ben
2010-05-30 14:24:06
@Ben: code updated. Change "resizeColumn" to the column you want to get resized.
Hans Passant
2010-05-30 14:30:27
Thanks a lot Hans, appreciate it!
Ben
2010-05-30 14:32:41
@Ben, this wasn't helpful? Sounds like it was, a "this was helpful" upvote is appropriate perhaps.
Hans Passant
2010-05-30 14:36:42