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 7862067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:59:02+00:00 2026-06-02T22:59:02+00:00

I have implemented the SortableSearchableList class found at http://msdn.microsoft.com/en-us/library/aa480736.aspx and have added a Sort

  • 0

I have implemented the SortableSearchableList class found at http://msdn.microsoft.com/en-us/library/aa480736.aspx and have added a Sort method to it as follows:

public void Sort(PropertyDescriptor prop, ListSortDirection direction)
{
ApplySortCore(prop, direction);
}

This class works when sorting my DataGridView by clicking on any of the column headers, but I need to be able to programmatically call the Sort method for a specified column (using a sortButton control in this example). The few code examples I’ve found online suggest obtaining the PropertyDescriptor for the column and passing it along to the ApplySortCore method. I have yet to get that to work. I can get the PropertyDescriptorCollection properties of either my DataGridView or SortableSearchableList, but can’t seem to get the Find method to obtain the PropertyDescriptor for my specified column/member. Here’s the rest of my code:

namespace SortableBindingListTest
{
public partial class Form1 : Form
{
    private SortableSearchableList<Tags> alarms = new SortableSearchableList<Tags>();
    public Form1()
    {
        InitializeComponent();
        alarms.Add(new Tags("some text", "1"));
        alarms.Add(new Tags("more text", "2"));
        alarms.Add(new Tags("another one", "3"));
        dataGridView1.AutoGenerateColumns = false;
        dataGridView1.AllowUserToAddRows = true;
        dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
        dataGridView1.RowHeadersVisible = false;
        dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
        DataGridViewTextBoxColumn alarmColumn = new DataGridViewTextBoxColumn();
        alarmColumn.DataPropertyName = "Alarm";
        alarmColumn.Name = "Alarm";
        alarmColumn.HeaderText = "Alarm";
        DataGridViewTextBoxColumn messageColumn = new DataGridViewTextBoxColumn();
        messageColumn.DataPropertyName = "Message";
        messageColumn.Name = "Message";
        messageColumn.HeaderText = "Message";
        dataGridView1.Columns.Add(alarmColumn);
        dataGridView1.Columns.Add(messageColumn);
        dataGridView1.DataSource = alarms;
    }

    private void sortButton_Click(object sender, EventArgs e)
    {
        // try getting properties of BindingList
        PropertyDescriptorCollection listProperties = TypeDescriptor.GetProperties(alarms);
        PropertyDescriptor alarmProp = listProperties.Find("Alarm", false);
        // prop is null at this point, so the next line fails
        alarms.Sort(alarmProp, ListSortDirection.Ascending);
        // try getting properties of DataGridView column
        PropertyDescriptorCollection dgvProperties = TypeDescriptor.GetProperties(dataGridView1);
        PropertyDescriptor columnProp = dgvProperties.Find("Alarm", false);
        // columnProp is null at this point, so the next line also fails
        alarms.Sort(columnProp, ListSortDirection.Ascending);
    }
}

public class Tags : INotifyPropertyChanged
{
    private string _alarm;
    private string _message;
    public event PropertyChangedEventHandler PropertyChanged;
    public Tags(string alarm, string message)
    {
        _alarm = alarm;
        _message = message;
    }

    public string Alarm
    {
        get { return _alarm; }
        set
        {
            _alarm = value;
            this.NotifyPropertyChanged("Alarm");
        }
    }
    public string Message
    {
        get { return _message; }
        set
        {
            _message = value;
            this.NotifyPropertyChanged("Message");
        }
    }
    private void NotifyPropertyChanged(string name)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(name));
    }
}
}

Any help would be greatly appreciated.

  • 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-06-02T22:59:05+00:00Added an answer on June 2, 2026 at 10:59 pm

    Try this

    dataGridView1.Sort(dataGridView.Columns[0],ListSortDirection.Ascending);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the SortedBindingList class shown at http://www.martinwilley.com/net/code/forms/sortablebindinglist.html I have then successfully added
I have implemented arbitrary links in my rtb using the CodeProject found here .
I have implemented an ASP.NET http handler. It appears to me that there is
I have implemented a python webserver. Each http request spawns a new thread. I
I have implemented VirtualPathProvider class so I can keep all my views in the
I have implemented a simple linked list class and I would now like to
I have implemented background worker class something similar to below sample and I want
I have implemented INotifyPropertyChanged to the following class public class FactoryItems : INotifyPropertyChanged {
I have implemented my own manual method of switching the app's localization within the
I have implemented software which have a DLL library which contains a set of

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.