Why does it incist SubItems is undefined by Controls.ListView?
I can add items just fine BUT as soon as I even think about trying other columns...
ListViewItem listItem = new ListViewItem();
listItem.Content = feed.Title.Value;
lvLately.Items.Add(listItem.Content);
listItem.Content = feed.Link.Value;
lvLately.SubItems.Add(listItem.Content);
ListViewItem lvLately = new ListViewItem("Bob");
lvLately.SubItems.Add("13");
lvLately.SubItems.Add("Other stuff");
Error 1 'System.Windows.Controls.ListView' does not contain a definition for 'SubItems' and no extension method 'SubItems' accepting a first arg开发者_JS百科ument of type 'System.Windows.Controls.ListView' could be found (are you missing a using directive or an assembly reference?) C:\Users\Tommo\documents\visual studio 2010\Projects\Morning\Morning\MainWindow.xaml.cs 185 34 Morning
I think you're confusing with the Windows Forms ListView
, which has sub-items (but it's a property of ListViewItem
, not ListView
).
In WPF there is no such thing as sub-items, there are only items. You can display multiple columns by using a GridView
as the View
for the ListView
. You can do it in code, but it's much easier in XAML. And anyway, you need to use data binding for this... I don't think there's an easy way to do it without bindings.
If you want to learn WPF, I suggest you forget what you learned in WinForms... The framework is completely different, and if you try to code in WPF the way you did in WinForms, you'll find yourself constantly fighting the API. Use XAML, use templates, use data binding. If you don't, you will end up hating WPF...
精彩评论