By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,407 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,407 IT Pros & Developers. It's quick & easy.

Listview will not resize after first time

P: n/a
Why doesn't the listview columns resize automatically after the first time
the listview is populated.
Or if you run the sub twice.

Private Sub LoadLV
lvProjects.SuspendLayout()
lvProjects.Clear()
lvProjects.View = View.Details
lvProjects.FullRowSelect = True
lvProjects.Columns.Add("Id", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Name", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Last Used", -1, HorizontalAlignment.Center)
lvProjects.Columns.Add("Status", 100, HorizontalAlignment.Center)
Dim a() As ListViewItem
Dim iRecs As Int16 = 0
Dim Litem As ListViewItem
Dim cn As New MySqlConnection(cAppc.ConnectionString)
Dim dr As MySqlDataReader
Dim sql As String = "select projectid,description,lastused from projects
order by projectid asc"
Dim cmd As New MySqlCommand(sql, cn)
cn.Open()
dr = cmd.ExecuteReader
Do While dr.Read
Litem = New ListViewItem(dr.GetInt16(0).ToString("00#"))
Litem.ImageIndex = 0
Litem.SubItems.Add(dr.GetString(1))
Litem.SubItems.Add(dr.GetDateTime(2).ToString("ddd MM/dd/yyyy"))
Litem.SubItems.Add("Idle")
ReDim Preserve a(iRecs)
a(iRecs) = Litem
Litem = Nothing
iRecs += 1
Loop
dr.Close()
cmd.Dispose()
cn.Close()
If Not IsNothing(a) Then lvProjects.Items.AddRange(a)
lvProjects.ResumeLayout()
lvProjects.Focus()
End Sub
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Cor
Hi Chad,

I cannot see what has to resize?

Can you be a little bit more precise?

For me it looks that after the clear of the listview you build the columns
everytime again, but maybe you do mean something else?

Cor
Why doesn't the listview columns resize automatically after the first time
the listview is populated.
Or if you run the sub twice.

Private Sub LoadLV
lvProjects.SuspendLayout()
lvProjects.Clear()
lvProjects.View = View.Details
lvProjects.FullRowSelect = True
lvProjects.Columns.Add("Id", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Name", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Last Used", -1, HorizontalAlignment.Center)
lvProjects.Columns.Add("Status", 100, HorizontalAlignment.Center)
Dim a() As ListViewItem
Dim iRecs As Int16 = 0
Dim Litem As ListViewItem
Dim cn As New MySqlConnection(cAppc.ConnectionString)
Dim dr As MySqlDataReader
Dim sql As String = "select projectid,description,lastused from projects
order by projectid asc"
Dim cmd As New MySqlCommand(sql, cn)
cn.Open()
dr = cmd.ExecuteReader
Do While dr.Read
Litem = New ListViewItem(dr.GetInt16(0).ToString("00#"))
Litem.ImageIndex = 0
Litem.SubItems.Add(dr.GetString(1))
Litem.SubItems.Add(dr.GetDateTime(2).ToString("ddd MM/dd/yyyy"))
Litem.SubItems.Add("Idle")
ReDim Preserve a(iRecs)
a(iRecs) = Litem
Litem = Nothing
iRecs += 1
Loop
dr.Close()
cmd.Dispose()
cn.Close()
If Not IsNothing(a) Then lvProjects.Items.AddRange(a)
lvProjects.ResumeLayout()
lvProjects.Focus()
End Sub

Nov 20 '05 #2

P: n/a
In the listview control you can have it automatically size to the width of
the longest item in that column if you use the -1 parameter when building a
column. It works the first time you populate the listview but every time
after that it shrinks the column to 0. Yes I do clear the listview each
time, I have tried it both ways clearing and not.

"Cor" <no*@non.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Chad,

I cannot see what has to resize?

Can you be a little bit more precise?

For me it looks that after the clear of the listview you build the columns
everytime again, but maybe you do mean something else?

Cor
Why doesn't the listview columns resize automatically after the first time the listview is populated.
Or if you run the sub twice.

Private Sub LoadLV
lvProjects.SuspendLayout()
lvProjects.Clear()
lvProjects.View = View.Details
lvProjects.FullRowSelect = True
lvProjects.Columns.Add("Id", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Name", -1, HorizontalAlignment.Left)
lvProjects.Columns.Add("Last Used", -1, HorizontalAlignment.Center)
lvProjects.Columns.Add("Status", 100, HorizontalAlignment.Center)
Dim a() As ListViewItem
Dim iRecs As Int16 = 0
Dim Litem As ListViewItem
Dim cn As New MySqlConnection(cAppc.ConnectionString)
Dim dr As MySqlDataReader
Dim sql As String = "select projectid,description,lastused from projects
order by projectid asc"
Dim cmd As New MySqlCommand(sql, cn)
cn.Open()
dr = cmd.ExecuteReader
Do While dr.Read
Litem = New ListViewItem(dr.GetInt16(0).ToString("00#"))
Litem.ImageIndex = 0
Litem.SubItems.Add(dr.GetString(1))
Litem.SubItems.Add(dr.GetDateTime(2).ToString("ddd MM/dd/yyyy"))
Litem.SubItems.Add("Idle")
ReDim Preserve a(iRecs)
a(iRecs) = Litem
Litem = Nothing
iRecs += 1
Loop
dr.Close()
cmd.Dispose()
cn.Close()
If Not IsNothing(a) Then lvProjects.Items.AddRange(a)
lvProjects.ResumeLayout()
lvProjects.Focus()
End Sub


Nov 20 '05 #3

P: n/a
Hi Chad,

It was a wise move to re-post the question, but I didn't get to see this one and
answered you earlier on - in the other thread. ;-)

Regards,
Fergus
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.