My dynamically created ListViewItems are not displaying in my ListView

Go To StackoverFlow.com

0

I am dynamically creating ListViewItem descendants:

class Application : ListViewItem {
. . .
class LegacyApplication : Application {

I store these first in a List of obects:

private List<object> legacyApps = new List<object>();

..this way:

if (ldbc.appIsLegacy(sPathOfExe)) {
  legacyApp = new LegacyApplication(sApp, sTitle, sDesc, sIconFileName, sPathOfExe, appCategoriesForCurrentApp);
} 
legacyApps.Add(legacyApp);

...and then I add them to the ListView on the main form this way:

foreach (LegacyApplication LegApp in legacyApps) {
  this.listApplications.Items.Add(LegApp);
}

...but the ListView does not display them. It displays the ListView Groups I've created (and each ListViewItem is assigned to one of those groups), but not the ListViewItems themselves...

Updated with requested info:

The constructor for the ListViewItem descendant looks like so:

public LegacyApplication(String AAppName, String ATitle, String ADesc, String AIconFileName, String APathOfExe, List<String> ACategories) {
  base.Name = String.Format("legapplvi{0}", AAppName);
  base.Text = ATitle; // "Title" is a short description - between exe name and Description 
  base.ToolTipText = ADesc;
  base.EnsureVisible();
  // "base" above means ListViewItem; "base" below refers to our Application class*
  base.Categories = ACategories;
  base.ExePath = APathOfExe;
  base.IconFileName = AIconFileName;
}
  • which adds the following properties to ListViewItem:

public string ExePath public string IconFileName public string Category public List Categories

LegacyApplication adds no further properties to (our) Application class.

I'm not sure what the respondent below means by "subitems" - the ListViewItems are subitems of the ListView Groups, perhaps...?

Updated with unrequested info (TMI?):

OK, I'm thinking I can add columns this way, once all the Groups are assigned to the ListView:

for(var item in listApplications.Groups)    {
       listApplications.Columns.Add(item)    
}

...but now, how do I add specific ListViewItems to particular columns?

Updated after getting it to (sort of) work:

Commenting out this:

listApplications.View = View.Details;

...gets the Items to show. HOWEVER, the Text is truncated, which caused me to pose another question here:

I need to display the entire Text of my ListViewItems (not truncated)

2012-04-03 20:10
by B. Clay Shannon
Can you provide a little bit more detail about how you're setting Text and SubItems in the ListViewItem within the class that is subclassing ListViewItem? Also, what are the properties of your ListView - scwagner 2012-04-03 20:13
Sure; I'll append it above - B. Clay Shannon 2012-04-03 20:43
If you use View = Details then don't forget to add ColumnHeaders. Without any you won't see the added item - Hans Passant 2012-04-03 20:54
I was referring to SubItems because I was (mistakenly) assuming that you were using the Details display mode. I don't see anything immediately obviously wrong with what you have provided, sorry - scwagner 2012-04-03 21:05
Can you also add a Xaml for you ListView? I am curious about that are these group - Nikolay 2012-04-03 21:23
It seems you have 2 things going on here and I don't see anything that shows the inheritance of the default ListView control. My initial response would be to start with a 'regular' aspx page with a ListView control directly on the page and use template bindings to get your issues cleared up...then extract it into a control, being sure to inherit from the ListView control - beauXjames 2012-04-03 22:12
I don't have xaml - this is WinForms, not WP - B. Clay Shannon 2012-04-03 22:44
I'm adding a response to a comment above, in the original post - B. Clay Shannon 2012-04-03 22:46
I do have: listApplications.View = View.Details; although I can't recall now why I added that (I read something somewhere that recommended it, but can't remember where or why) - B. Clay Shannon 2012-04-03 22:49
Thanks for the hint scwagner; commenting out the line: listApplications.View = View.Details; causes progress to be made - it's 9 times uglier than a bag of butts, but I am seeing the Titles for the ListViewItems now.. - B. Clay Shannon 2012-04-03 22:51
@beauXjames: This is a WinForms project, not asp.net or so (not a web project - B. Clay Shannon 2012-04-03 22:52


1

Did you try to create a ListViewItem first and then add into the List instead of using this.listApplications.Items.Add(LegApp);

Can you provide more details with a code snippet

2012-04-04 08:05
by las
I got it working -- although I can't recall exactly how at the moment - B. Clay Shannon 2012-04-05 04:41