How to enable user to click anywhere on header to sort by that column?

Posted by: frankchen on 8 September 2017, 2:44 pm EST

  • Posted 8 September 2017, 2:44 pm EST

    My programs is:

    public Form1()
            {
                InitializeComponent();
                var table = new DataTable();
                table.Columns.Add("Col1");
                table.Columns.Add("Col2");
                var row = table.NewRow();
                row[0] = 1;
                row[1] = "T";
                table.Rows.Add(row);

                row = table.NewRow();
                row[0] = 3;
                row[1] = "S";
                table.Rows.Add(row);

                fpSpread1_Sheet1.DataSource = table;
                foreach (Column col in fpSpread1_Sheet1.Columns)
                {
                    col.AllowAutoSort = true;
                    col.ShowSortIndicator = true;
                    col.TextIndent = 0;
                    col.HorizontalAlignment = CellHorizontalAlignment.Left;
                }
               
            }

    but currently, it only works if user clicks on small blank area to the right of the column herader, that is only clicking on the sort indicator can sort that column.

    how to eable user to click anywhere of the column header to sort?

    Thanks

    Frank

  • Replied 8 September 2017, 2:44 pm EST

    Hello Frank,

    You can sort the rows using the SortRows method, to enable the user to sort the column as soon as the user clicks any where in the column header.  I have created a sample in which, when the user clicks on the column header, the column gets sorted in ascending order, kindly have a look at the sample.

    Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur.


    2011/08/sortcolheader.zip
  • Replied 8 September 2017, 2:44 pm EST

    Thank you! I will have a try and let you know the result.

  • Replied 8 September 2017, 2:44 pm EST

    It works!

    Thank you!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels