Christophe1245
New member
- Joined
- Nov 6, 2010
- Messages
- 2
- Programming Experience
- 1-3
Hi Forum,
I'm just starting with vb.net and I'm facing a problem that would probably be relatively easy to fix for experienced developers like you.
I'm using the next class to fill my listview
Now my problem:
I want all the listview columns to be in auto width. I tried adding the next line of code but then only my first column fills my entering listview width. All other columns are not affected!
Can someone help me with this?
Thanks in advance en sorry for my bad english.
Best regards,
Christophe
I'm just starting with vb.net and I'm facing a problem that would probably be relatively easy to fix for experienced developers like you.
I'm using the next class to fill my listview
VB.NET:
Imports System.Data.SqlClient
Public Class ListViewData
Public Sub FillListView(ByRef MyListView As ListView, _
ByRef myData As SqlDataReader)
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim shtCntr As Short
MyListView.Clear()
For shtCntr = 0 To myData.FieldCount() - 1
lvwColumn = New ColumnHeader()
lvwColumn.Text = myData.GetName(shtCntr)
MyListView.Columns.Add(lvwColumn)
Next
Do While myData.Read
itmListItem = New ListViewItem()
itmListItem.Text = myData(0)
For shtCntr = 1 To myData.FieldCount() - 1
If myData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(myData.GetString(shtCntr))
End If
Next shtCntr
MyListView.Items.Add(itmListItem)
Loop
End Sub
End Class
Now my problem:
I want all the listview columns to be in auto width. I tried adding the next line of code but then only my first column fills my entering listview width. All other columns are not affected!
VB.NET:
lvwColumn.Width = -2
Can someone help me with this?
Thanks in advance en sorry for my bad english.
Best regards,
Christophe