Click here to Skip to main content
12,242,812 members (41,334 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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.

// 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());
public ListViewItem getSize(string eachFile)
        {
            FileInfo f = new FileInfo(eachFile);
            long fileSize = f.Length;
            
            ListViewItem FileSize = new ListViewItem(fileSize.ToString());
            return FileSize;
Posted 24-Jan-13 4:57am
Edited 24-Jan-13 5: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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100