Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 955327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:21:49+00:00 2026-05-16T00:21:49+00:00

I have a gridview …with multiple columns. If I click on one column, it

  • 0

I have a gridview …with multiple columns. If I click on one column, it sorts the gridview based on that column values. I like to add an arrow in that “clicked” column header(when user clicks) to show that “this particular column is clicked and this is the sort direction”

How can I do this?

I saw a sample link
How to I display a sort arrow in the header of a list view column using C#?

but its uses Windows.Forms.ListView..but i am using Windows.Controls.Listview 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:21:50+00:00Added an answer on May 16, 2026 at 12:21 am

    I used this tutorial to solve the same problem you have:
    http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-2-sorting

    It contains a solution by using a custom Adorner, which is added to the ListView-Header.

    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Collections.ObjectModel;
    using System.Windows.Shapes;
    using System.ComponentModel;
    using System.Windows.Media;
    using System.Windows.Documents;
    
    namespace ListViewTest3
    {
      public partial class ListViewTest : Window
      {
        private ObservableCollection<GameData> _GameCollection =
            new ObservableCollection<GameData>();
    
        private GridViewColumnHeader _CurSortCol = null;
        private SortAdorner _CurAdorner = null;
    
        public ListViewTest()
        {
          _GameCollection.Add(new GameData {
              GameName = "World Of Warcraft",
              Creator = "Blizzard",
              Publisher = "Blizzard" });
          _GameCollection.Add(new GameData {
              GameName = "Halo",
              Creator = "Bungie",
              Publisher = "Microsoft" });
          _GameCollection.Add(new GameData {
              GameName = "Gears Of War",
              Creator = "Epic",
              Publisher = "Microsoft" });
    
          InitializeComponent();
        }
    
        public ObservableCollection<GameData> GameCollection
        { get { return _GameCollection; } }
    
        private void AddRowClick(object sender, RoutedEventArgs e)
        {
          _GameCollection.Add(new GameData {
              GameName = "A New Game",
              Creator = "A New Creator",
              Publisher = "A New Publisher" });
        }
    
        private void SortClick(object sender, RoutedEventArgs e)
        {
          GridViewColumnHeader column = sender as GridViewColumnHeader;
          String field = column.Tag as String;
    
          if (_CurSortCol != null)
          {
            AdornerLayer.GetAdornerLayer(_CurSortCol).Remove(_CurAdorner);
            gameListView.Items.SortDescriptions.Clear();
          }
    
          ListSortDirection newDir = ListSortDirection.Ascending;
          if (_CurSortCol == column && _CurAdorner.Direction == newDir)
            newDir = ListSortDirection.Descending;
    
          _CurSortCol = column;
          _CurAdorner = new SortAdorner(_CurSortCol, newDir);
          AdornerLayer.GetAdornerLayer(_CurSortCol).Add(_CurAdorner);
          gameListView.Items.SortDescriptions.Add(
              new SortDescription(field, newDir));
        }
      }
    
      public class GameData
      {
        public string GameName { get; set; }
        public string Creator { get; set; }
        public string Publisher { get; set; }
      }
    
      public class SortAdorner : Adorner
      {
        private readonly static Geometry _AscGeometry =
            Geometry.Parse("M 0,0 L 10,0 L 5,5 Z");
        private readonly static Geometry _DescGeometry =
            Geometry.Parse("M 0,5 L 10,5 L 5,0 Z");
    
        public ListSortDirection Direction { get; private set; }
    
        public SortAdorner(UIElement element, ListSortDirection dir)
          : base(element)
        { Direction = dir; }
    
        protected override void OnRender(DrawingContext drawingContext)
        {
          base.OnRender(drawingContext);
    
          if (AdornedElement.RenderSize.Width < 20)
            return;
    
          drawingContext.PushTransform(
              new TranslateTransform(
                AdornedElement.RenderSize.Width - 15,
                (AdornedElement.RenderSize.Height - 5) / 2));
    
          drawingContext.DrawGeometry(Brushes.Black, null,
              Direction == ListSortDirection.Ascending ?
                _AscGeometry : _DescGeometry);
    
          drawingContext.Pop();
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.