locked
Problem in selecting listview subitems in WPF RRS feed

  • Question

  • Hi Everybody,

                    I'm new to wpf. But i know winforms. Now i'm doing listview. I want to select listview subitems in wpf.

    Please help me

    • Moved by Mike Danes Tuesday, July 16, 2013 8:07 PM WPF specific
    Tuesday, July 16, 2013 11:21 AM

Answers


  • A ListItem doesn't have subitems in WPF. Instead you typically bind the ListView to a collection that contains objects of a custom type and define properties on this type:

    Code:

    public class YourType
    {
    public string Name {get;set;}
    }
    
    
    lstView.ItemsSource = new List<YourType>(){new YourType { Name = "some name..."}};
    


    XAML:

    <ListView x:Name="lstView">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Header" DisplayMemberBinding="{Binding Name}"/>
                    </GridView>
    ....
    </ListView>
    • Marked as answer by Lisa Zhu Saturday, July 27, 2013 7:22 AM
    Wednesday, July 17, 2013 2:22 PM

All replies

  • There is a extra WPF Fourm:

    http://social.msdn.microsoft.com/Forums/en-US/home?forum=wpf

    You mean you want to select listview items in Code behind?

    We need to see how you currently declare and fill the listview (XAML + Code), before we can give you any solutions.


    Let's talk about MVVM: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b1a8bf14-4acd-4d77-9df8-bdb95b02dbe2 Please mark post as helpfull and answers respectively.

    Tuesday, July 16, 2013 7:06 PM

  • A ListItem doesn't have subitems in WPF. Instead you typically bind the ListView to a collection that contains objects of a custom type and define properties on this type:

    Code:

    public class YourType
    {
    public string Name {get;set;}
    }
    
    
    lstView.ItemsSource = new List<YourType>(){new YourType { Name = "some name..."}};
    


    XAML:

    <ListView x:Name="lstView">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Header" DisplayMemberBinding="{Binding Name}"/>
                    </GridView>
    ....
    </ListView>
    • Marked as answer by Lisa Zhu Saturday, July 27, 2013 7:22 AM
    Wednesday, July 17, 2013 2:22 PM