For some reason, when I write the following code in my Visual Studio 2010 (.NET Framework 4.5):
ListViewItem item = new ListViewItem("item1");
item.SubItems
there is no such field as SubItems.
What could be the reason for that?
Regards, Vitalii.
For some reason, when I write the following code in my Visual Studio 2010 (.NET Framework 4.5):
ListViewItem item = new ListViewItem("item1");
item.SubItems
there is no such field as SubItems.
What could be the reason for that?
Regards, Vitalii.
Yes there is, at least in winforms.
Look a little closer, once you add the dot the usual list of items should come up:

ListViewItem item = new ListViewItem("item1");
item.SubItems.Add("subitem1");
Note: To declare an instance you need to reference the class like this:
ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem();
Also note: Sometimes Intellisense stops working; I have to restart VS to bring it back to life..
If however you are targeting WPF, then you are right: There are no SubItems in a WPF ListViewItem. It is a ContentControl, which can contain whatever you put there, I believe. But I'm no WPF expert. A good book may be best..
System.Windows.Controls.ContentControl System.Windows.Controls.ListBoxItem System.Windows.Controls.ListViewItem
There is a ListViewItem constructor that takes a string array, where the first element is the main item text and the other are the SubItems texts:
var myNewItem = new ListViewItem(new[]
{
"First column",
"Second column",
"Third column"
});
myListItem.Items.Add(myNewItem);
Of course, you have to set your ListView Mode to Detail mode, and create the Columns collection accordingly.
EDIT: This is a WinForm tip... I dont know if it applies to WPF unfortunately.