Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
I have an c# windowsform app with several forms and in one of the forms I have a 2 column listview. When I add the text to the items of the listview, nothing is shown. I know the items are getting added because the vertical scroll bar appears, and I checked that the items had the appropriate text in the debugger. Does anyone know why the text is not shown and how I can get them to appear? Apparently others have had this problem with listviews but I didn't see any solutions posted. The same thing happens in the listbox in another form - strings are getting added to the items of the listbox correctly but they are not shown. Thanks in advance.

Boy, do I feel stupid! I assumed the text color was defaulted to black but it was white, same as the backgound color. Thanks for your help!

Oops, maybe I was too hasty. That was the problem with the listbox but not the listview. The text color (fore color) for the listview was set to black and background color to white. Here is the code for the listview:

In load:
C#
columnHeader2.Text = "col 1";
columnHeader1.TextAlign = HorizontalAlignment.Center;
columnHeader1.Width = this.Width / 2 - 6;

columnHeader2.Text = "col 2";
columnHeader2.TextAlign = HorizontalAlignment.Center;
columnHeader2.Width = this.Width / 2 - 6;

lvwCOMMIO.Columns.Add(columnHeader1);
lvwCOMMIO.Columns.Add(columnHeader2);

When I try to update the listview: (message1 and message2 are strings)
C#
ListViewItem item1 = new ListViewItem(message1, 0);
item1.SubItems.Add(message2);

lvwCOMMIO.Items.Add(item1);

I was testing for InvokeRequired and using Invoke() with a delegate on the listview but it's false so I deleted that test.

Yes, I have the view type set to Details.
Posted
Updated 19-Oct-21 11:49am
v8
Comments
BillW33 22-Jul-11 13:01pm    
Have you checked to make sure that the color of your text is not the same as the background color?
OriginalGriff 22-Jul-11 14:11pm    
Show us the code that you use to add the text to the items - use the "Improve question" widget to edit your question and provide better information.
BillW33 22-Jul-11 14:49pm    
Yeah, the reason I thought of that right off is because I have had it happen to me in the past. ;)
DaveAuld 25-Jul-11 9:14am    
Have you changed the view type of the Listview to View.Details? See this page; http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.view.aspx

In windows forms. click on the listview box. You will see a small triangle thing. Click it, and change one of the drop down boxes to Details. It should show you what you want.
 
Share this answer
 
OwnerDraw (property) set to false?

You can easily, when moving about the properties windows of your listview, click OwnerDraw which is normally set to False, and set it to True.

If you do this - nothing will be drawn in the listview by default and you will need to access the 'Paint' event to draw your stuff. You will get lines added so you may see scroll bars appearing, but no text.

View - Details is common because we have to select that as it is not default setting.

OwnerDraw - Not usually thought of because the default (false) is normally what we want.

If not, try adding another ListView and compare default properties. Perhaps you altered a property unwittingly.
 
Share this answer
 
Comments
TheRealSteveJudge 20-Oct-21 5:26am    
Answering an eleven years old question makes no sense at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900