Listview not painting

bjwade62

Centurion
Joined
Oct 31, 2003
Messages
104
I have two listview controls. In the code below I'm copying each item from the left listview to the one on the right side. I have a statusbar showing the number of items in the right listview. It shows the correct number so I think they're getting added, just not painting. Oh yea... the column headings (which have text) show as blank. Any help?

Visual Basic:
        frmMain.lvwLeftList.BeginUpdate()
        For Each SelLeftItem In frmMain.lvwLeftList.Items
            SelLeftItem.ImageIndex = 1
            SelLeftItem.ForeColor = Color.Blue
            Dim SelItem As String = SelLeftItem.Text
            Dim tmpItem As ListViewItem = CType(SelLeftItem.Clone(), ListViewItem)
            frmMain.lvwRightList.Items.Add(tmpItem)
            frmMain.ToolStripStatusRightShown.Text = "Total: " & frmMain.lvwRightList.Items.Count
        Next
        frmMain.lvwLeftList.EndUpdate()
 
From what I can tell theres nothing wrong with the code you have posted, the problem could be elsewhere. Do both listviews have the same amount of columns? Are they both set as detailed view?

EDIT:- Oops i just noticed your calling BeginUpdate and EndUpdate on the left listview, but as you are adding the items to the right listview its that you should be calling them on.
 
Yes, both are set as detail and both have the same number of coulmns. Also, both have sorting set to none. I ran into this periodically with other code in my app but the portion I posted never works.

Cags said:
From what I can tell theres nothing wrong with the code you have posted, the problem could be elsewhere. Do both listviews have the same amount of columns? Are they both set as detailed view?
 
Did some experimenting. If I change the view property to anything except Details it works fine. However I need it set to Details. The other settings don't give me what I'm looking for.

Cags said:
From what I can tell theres nothing wrong with the code you have posted, the problem could be elsewhere. Do both listviews have the same amount of columns? Are they both set as detailed view?

EDIT:- Oops i just noticed your calling BeginUpdate and EndUpdate on the left listview, but as you are adding the items to the right listview its that you should be calling them on.
 
Can anyone help me? Have I found a bug in the control? If so is there a third party control I can use? I really need to be able to set the properties to Details or something similar.

bjwade62 said:
Did some experimenting. If I change the view property to anything except Details it works fine. However I need it set to Details. The other settings don't give me what I'm looking for.
 
I found a work around. Further up in the code I had a listview.clear method called. I've found that if I remove each item one at a time through a loop the listview paints correctly. I still think it's a bug in the listview control though.

bjwade62 said:
Can anyone help me? Have I found a bug in the control? If so is there a third party control I can use? I really need to be able to set the properties to Details or something similar.
 
Here is your problem. There is a big difference between ListView.Clear and ListView.Items.Clear (I found this out the hard way too). ListView.Clear clears all the items, all the columns, and maybe some other properties (I'm not sure). If you are looking to simply remove all items, use ListView.Items.Clear.
 
Back
Top