tags:

views:

38

answers:

1

I want the ability to auto stretch the listview control column when the form gets resized in vb.net 2008

These are the properties I am mentioning for the ListView now :

 ListView1.View = View.Details
        'ListView1.GridLines = True
        ListView1.FullRowSelect = True
        ListView1.HideSelection = False
        ListView1.MultiSelect = True


        ListView1.Columns.Add("Listing", ListView1.Width, HorizontalAlignment.Center)


        ListView1.Items.Add("tet")

I am using form_resize event but it is not giving what I want

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        ListView1.Width = Me.Width
    End Sub

I am increasing the width of control and not columns as I wanted. I am unable to find anything else than width.

Any help?

Thanks.

A: 

Firstly, you do not have to set the Form1_Resize, you can achive this using the Anchor property of the ListView.

Set this to Top,Bottom,Left,Right

Secondly, try using the resize event of the ListView

Something like

Private Sub ListView1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.Resize
    If ListView1.Columns.Count > 0 Then
        ListView1.Columns(0).Width = ListView1.Width
    End If
End Sub
astander