Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to retrieve a single value from a listview
    primarykey
    data
    text
    <p>Brand new to C sharp so forgive me is this is a stupid question. I have a simple class:</p> <pre><code> public enum SexType { Male, Female }; public class User { public string Name { get; set; } public int Age { get; set; } public string Mail { get; set; } public SexType Sex { get; set; } } </code></pre> <p>Then I use the class to fill a list view by grouping.</p> <pre><code>public Window4() { InitializeComponent(); List&lt;User&gt; items = new List&lt;User&gt;(); items.Add(new User() { Name = "John Doe", Age = 42, Sex = SexType.Male }); items.Add(new User() { Name = "Jane Doe", Age = 39, Sex = SexType.Female }); items.Add(new User() { Name = "Sammy Doe", Age = 13, Sex = SexType.Male }); lvUsers.ItemsSource = items; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvUsers.ItemsSource); PropertyGroupDescription groupDescription = new PropertyGroupDescription("Sex"); view.GroupDescriptions.Add(groupDescription); } </code></pre> <p>Now all I want to be able to do is when a group is selected in the listview I want to be able to grab the individual items valuses. So if I clicked on the "John Doe" group in the listview I want to be able to get the Age(42) and Name(John Doe). So I went to the SelectedChanged method for the listview but when I select a record in the listview I can't get the individual values. When the SelectedChange fires and open the Immediate Window and if I look at ?listview.SelectedValue I get: {ListBoxSampleWPF.User} Age: 13 Mail: null Name: "Sammy Doe" Sex: Male So I know the values are there but if I try: ?lvUsers.SelectedItems.Age; I get: 'System.Collections.IList' does not contain a definition for 'Age' and no extension method 'Age' accepting a first argument of type 'System.Collections.IList' could be found (are you missing a using directive or an assembly reference?)</p> <p>Please let me know what I am doing wrong. Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload