Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Listview Access to SelectedItem and subitems
    text
    copied!<p>Ok, I am having more problems with my C# WPF ListView control. Here it is in all its glory:</p> <pre><code>&lt;Window x:Class="ebook.SearchResults" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="ISBNListView" Height="503" Width="1004"&gt; &lt;Grid&gt; &lt;ListView Name="listView1" Margin"22,30,33,28" MouseDoubleClick="getSelectedItem" &gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridView.Columns&gt; &lt;GridViewColumn Header="ISBN" Width="150" DisplayMemberBinding="{Binding ISBN}"/&gt; &lt;GridViewColumn Header="Title" Width="350" DisplayMemberBinding="{Binding Title}"/&gt; &lt;GridViewColumn Header="Author" Width="350" DisplayMemberBinding="{Binding Author}" /&gt; &lt;/GridView.Columns&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>I am filling the listView with the following:</p> <pre><code>XDocument xdoc = XDocument.Load(GlobalVars.docPath + "\\tempSearchResults.xml"); var items = from item in xdoc.Descendants("Book") select new { ISBN = item.Element("ISBN").Value, Title = item.Element("Title").Value, AuthTexts = item.Element("Author").Value }; foreach (var item in items) { listView1.Items.Add(new { ISBN = item.ISBN, Title = item.Title, Author = item.AuthTexts }); } </code></pre> <p>I am having a devil of a time retrieving data from a row when it is double clicked. The DoubleClick does popup a message box with all the data in the row, I just cannot seem to get only one subitem or cell's data. Say a row has ISBN: 1234567 Title: Hurrr Author: Waldo, how do I just retrieve the ISBN or just the title?</p> <pre><code>private void getSelectedItem(object sender, MouseButtonEventArgs e) { System.Windows.MessageBox.Show(listView1.SelectedItems[0].ToString()); } </code></pre> <p>Still new to C# and .Net and banging my head against the wall. I figure this should be rather simple.</p>
 

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