How do you show Combo Box in ListView when bound?

I am displaying many rows of data in a list view that is bound to a list of a custom class. A custom class has a property called a type. The number of types allowed is limited and I would like to restrict the user to make changes by choosing from a combobox. I tried to add the combobox to the base class, but it didn't show up as a list as a list.

+1


source to share


2 answers


Found this online and seemed like a good starting point to get started 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>

      

0


source


You need to use DataTemplate.



There are many tutorials available on the Internet.

0


source







All Articles