I am displaying many rows of data in a list view that is bound to a list of a custom class. The custom class has a property called type. The number of allowable Types is limited and I would like to limit the user to making changes by selecting from a combobox. I tried adding a combobox to the base class but that did not display as a combobox in the list view.
A:
You need to use a DataTemplate.
There are many tutorials available online.
thealliedhacker
2008-12-23 20:56:40
A:
Found this online and seemed like a good starting point to begin working with DataTemplates.
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/749c8e84-3af3-4ec9-90b1-297d684025e7/
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<XmlDataProvider x:Key="MyData" XPath="/Info">
<x:XData>
<Info xmlns="">
<Item ID="123" Catalog="Category1"/>
<Item ID="456" Catalog="Category2"/>
<Item ID="789" Catalog="Category3"/>
</Info>
</x:XData>
</XmlDataProvider>
<CollectionViewSource x:Key='src' Source="{Binding Source={StaticResource MyData}, XPath=Item}" />
</Window.Resources>
<Grid>
<ListView Name="mylist" ItemsSource="{Binding Source={StaticResource src}}">
<ListView.View>
<GridView>
<GridViewColumn Header="Catalog" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="mycombo" SelectedValue="{Binding XPath=@Catalog}">
<ComboBoxItem>Category1</ComboBoxItem>
<ComboBoxItem>Category2</ComboBoxItem>
<ComboBoxItem>Category3</ComboBoxItem>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="ID" Width="100" DisplayMemberBinding="{Binding XPath=@ID}" />
</GridView>
</ListView.View>
</ListView>
</Grid>