Sauron
Sauron

Reputation: 16923

Get HeaderClick event of a WPF listview

How can I get the headerclick event of a WPF Listview?

Upvotes: 3

Views: 5945

Answers (2)

IntegratedHen
IntegratedHen

Reputation: 473

just to expand on the previous answer, how to know which header was clicked on:

XAML:

<ListView GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler">

CS:

private void SortHeaderClick(object sender, RoutedEventArgs e)
{
    MessageBox.Show(((GridViewColumnHeader)e.OriginalSource).Column.Header.ToString());
}

Upvotes: 2

Matt Hamilton
Matt Hamilton

Reputation: 204239

You can use the GridViewColumnHeader.Click attached event. As an example, see the MSDN page on sorting a GridView when the header is clicked.

<ListView x:Name='lv' 
          Height="150" 
          HorizontalAlignment="Center" 
          VerticalAlignment="Center" 
          GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler">

Upvotes: 11

Related Questions