How to tell which column of a ListView was clicked

Hi Experts,

     I have a ListView in a WPF Window.  I need to do certain things based on the particular column of a row that the user picks on.  Basically if the user clicks on the Info icon in that column I want to not select the row, but rather just pop-up a window and display information specific to the item that is stored in that row.  If the user clicks on any other column of the row, then I want to select the row and trigger a whole different set of code.  How can I do that?  I can retrieve the selected row, but I have no way to know which column was clicked. Or do I?

Thanks!
axnst2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
I don't know if this is the kind of example that you need, but it shows how to configure a ListViewItem for a popup.

Popup Class
http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup.aspx#1

<Window x:Class="LdiaryPopupToolTip.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="How To Use a Popup Window as a ListViewItem ToolTip (Sample created by Ldiary)" Height="200" Width="250">    
 <StackPanel Name="motherPanel">        
   <Popup  Height="Auto" Width="Auto" Name="listViewItemToolTip" StaysOpen="True" AllowsTransparency="True"  >            
    <Border BorderThickness="2" Background="ForestGreen" >                
     <StackPanel Margin="20"  Orientation="Horizontal">                    
      <TextBlock Text="Age is "/>                    
      <TextBlock  Name="popupTextBlock" />                    
      <TextBlock Text=" yrs old."/>                
     </StackPanel>            
    </Border>        
   </Popup>        
 <ListView ItemsSource="{Binding}">            
  <ListView.ItemContainerStyle>                
   <Style TargetType="{x:Type ListViewItem}">                    
    <EventSetter Event="Mouse.MouseEnter" Handler="Get_Ldiary_PopupToolTip" />                    
    <EventSetter Event="Mouse.MouseLeave" Handler="Remove_Ldiary_PopupToolTip"/>                
   </Style>            
</ListView.ItemContainerStyle>            
  <ListView.View>                
   <GridView >                    
    <GridView.Columns>                        
     <GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=First}" />                        
     <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=Last}" />                    
    </GridView.Columns>                
   </GridView>            
  </ListView.View>        
 </ListView>    
 </StackPanel>
</Window>

Open in new window


using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Windows.Controls.Primitives;
 
namespace LdiaryPopupToolTip
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            List<Person> lst = new List<Person>();
            Person ps = new Person();
            ps.First = "Ldiary";
            ps.Last = "Translations";
            ps.Age = "21";
            lst.Add(ps);
            ps = new Person();
            ps.First = "L";
            ps.Last = "English";
            ps.Age = "30";
            lst.Add(ps);
            ps = new Person();
            ps.First = "Diary";
            ps.Last = "Japanese";
            ps.Age = "19";
            lst.Add(ps);
            motherPanel.DataContext = lst;
        }
 
        private void Get_Ldiary_PopupToolTip(object sender, MouseEventArgs e)
        {
            ListViewItem listViewItem = e.Source as ListViewItem;
            Person person = listViewItem.Content as Person;
            popupTextBlock.Text = person.Age;
            listViewItemToolTip.PlacementTarget = listViewItem;
            listViewItemToolTip.Placement = PlacementMode.MousePoint;
            listViewItemToolTip.IsOpen = true;
        }
        private void Remove_Ldiary_PopupToolTip(object sender, MouseEventArgs e)
        {
            listViewItemToolTip.IsOpen = false;
        }
 
    }
 
    public class Person
    {
        private string _first;
        public string First
        {
            get { return _first; }
            set { _first = value; }
        }
        private string _last;
        public string Last
        {
            get { return _last; }
            set { _last = value; }
        }
        private string _age;
        public string Age
        {
            get { return _age; }
            set { _age = value; }
        }
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
axnst2Author Commented:
That is not what I was looking for and to be honest after researching it I don't think that there is a way to do this...
0
axnst2Author Commented:
I basically have a column that shows an image of a question mark.  When the user clicks the image I want to display certain things about the record.  If the user clicks on the record under any other column header, I am supposed to process the record (In this case update its business state and move it to the end of the list)  So I need to know which column was clicked on and I don't think there is a way to know this under WPF.  Unless I am wrong...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.