Lock Listview column width

HI All,

I'm trying to lock the widths of a listview in vb.net 2005. There is no setting on the control for this.

How can I achieve this?

Thanks,
Sean
LVL 1
nzfireAsked:
Who is Participating?
 
lojkConnect With a Mentor .Net and Infrastructure ConsultantCommented:
Agreed a datagrid is often better but listviews have their benefits (to the users expectations at least)....

Either way this should work... Please delete the appropriate chunk as required.

    Private Sub ListView1_ColumnWidthChanging(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnWidthChangingEventArgs) Handles ListView1.ColumnWidthChanging
       
        ''either for single column locking
        Select Case e.ColumnIndex
            Case 0, 1 'ie if its the first or second column
                e.Cancel = True  'abort the event
        End Select

        'or to just prevent all resizing.
        e.Cancel = True

    End Sub
 
0
 
planoczCommented:
If you want to lock the widths you should use a datagrid.
0
 
nzfireAuthor Commented:
Perfect, thanks
0
 
lojk.Net and Infrastructure ConsultantCommented:
cool, kinda reminded that i should be using a few more listviews!

happy to help, thanks for the points...
0
 
johnhjacksonCommented:
This doesn't work for me.  It prevents the viewing of the resizing, but in the end the colulmn still gets resized to any width the user wants.
0
All Courses

From novice to tech pro — start learning today.