I am having trouble adding a row that displays all the values of the member of an object.
Here is how I have set up my listview:
<ListView Height="178" HorizontalAlignment="Left" Margin="238,31,0,0" Name="SpoolSheetListView" VerticalAlignment="Top" Width="555" HorizontalContentAlignment="Stretch" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="85" Header="Column 1" />
<GridViewColumn Width="120" Header="Column 2" />
<GridViewColumn Width="120" Header="Column 3" />
<GridViewColumn Width="120" Header="Column 4" />
<GridViewColumn Width="115" Header="Column 5" />
</GridView>
</ListView.View>
</ListView>
say, myObject has 5 members: member1 to member5, which are all of type string. How do I add a single row in the ListView for that object?
Thanks again people!
WPF list controls work best when you use them with data binding; you should bind the
ItemsSourceof theListViewto a list of objects, and bind each column to a property of these objects.(
Itemsbeing a property of theDataContextthat returns a collection of objects)To add a row to the
ListView, you just need to add an item to theItemscollection (note that the collection should implementINotifyCollectionChangedso that theListViewis notified; theObservableCollection<T>class works fine for most cases)