Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can anybody please tell me why i'm getting the words "ListViewItem: {data here}" in my ListView SubItem columns. In other words when i run my Win Forms application, in each column of my ListView where i have subItems of data, the actual words 'ListViewItem ...' are appearing just before the data itself - which is displayed in curly braces.

This wasn't happening until i was tidying some code up. I'm hoping it's a simple mistake.

Here is the code which calls my method. And the method (or part of) is shown underneath.

C#
// ListView1
            string[] checkedINfileList = Directory.GetFiles("O:\\TestDaws\\CSDB\\CheckedIN");
            
           foreach (string file in checkedINfileList)
            {
            
                ListViewItem itemName = list1.getName(file);
                ListViewItem itemSize = list1.getSize(file);
                ListViewItem itemModified = list1.getDate(file);
             
                listView1.Items.Add(itemName);
                itemName.SubItems.Add(itemSize.ToString() + " Kb");
                itemName.SubItems.Add(itemModified.ToString());

C#
public ListViewItem getSize(string eachFile)
        {
            FileInfo f = new FileInfo(eachFile);
            long fileSize = f.Length;
            
            ListViewItem FileSize = new ListViewItem(fileSize.ToString());
            return FileSize;
Posted
Updated 24-Jan-13 4:35am
v3
Comments
Kishor Deshpande 24-Jan-13 9:59am    
Code please..
DaedalusAero 24-Jan-13 10:36am    
Please see revised question above for code. Thanks in advance.

1 solution

Because that is what the default ToString overridde of ListViewItem does: Prints the name ofg the class "ListViewItem" followed by a colon, and then the data content in curly brackets.
C#
ListViewItem lvi = new ListViewItem("hello");
Console.WriteLine(lvi);
Will print
ListViewItem: {hello}
I assume that you have removed a class which derived from ListViewItem, and which overrode ToString to produce the output you wanted.
 
Share this answer
 
Comments
DaedalusAero 24-Jan-13 10:49am    
Many thanks. I had managed to break it by fiddling - that pointed me in the right direction. Thanks again.
OriginalGriff 24-Jan-13 10:55am    
You're welcome!

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