locked
How to set the ListViewItemSorter Property RRS feed

  • Question

  • I'm making codes to sort by headercolumn click of the listview control.

    I followed the code in this site.

    However an error occur when compiled.

    Error	1	Cannot implicitly convert type 'WindowsApplication1.ListViewColumnSorter' to 'System.Collections.IComparer'. An explicit conversion exists (are you missing a cast?)	C:\CSharpSample\ColulmHeaderSortTest\WindowsApplication1\WindowsApplication1\Form1.cs	20
    

    The error occur when set the ListViewItemSorter property.

    private ListViewColumnSorter lvwColumnSorter;
    public Form1()
    {
        InitializeComponent();
        // Create an instance of a ListView column sorter and assign it 
        // to the ListView control.
        lvwColumnSorter = new ListViewColumnSorter();
        this.listView1.ListViewItemSorter = lvwColumnSorter;// Error!
    }
    Can anybody give me some advice?


    • Moved by CoolDadTx Friday, September 20, 2019 9:27 PM Winforms related
    Friday, September 20, 2019 6:50 PM

Answers

  • Is this were you got the code? If so and you followed instructions to the T and still have issues post a question at the bottom of the page below.

    https://www.codeproject.com/Articles/5332/ListView-Column-Sorter


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Jeff0803 Saturday, September 21, 2019 9:23 PM
    Friday, September 20, 2019 9:08 PM
  • I found my code has missed some.

    public class ListViewColumnSorter should be inherited from IComparer but I didn't

    After change it, works fine!

    Thanks!

    • Marked as answer by Jeff0803 Tuesday, September 24, 2019 1:48 PM
    Saturday, September 21, 2019 9:25 PM

All replies

  • Is this were you got the code? If so and you followed instructions to the T and still have issues post a question at the bottom of the page below.

    https://www.codeproject.com/Articles/5332/ListView-Column-Sorter


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Jeff0803 Saturday, September 21, 2019 9:23 PM
    Friday, September 20, 2019 9:08 PM
  • I found my code has missed some.

    public class ListViewColumnSorter should be inherited from IComparer but I didn't

    After change it, works fine!

    Thanks!

    • Marked as answer by Jeff0803 Tuesday, September 24, 2019 1:48 PM
    Saturday, September 21, 2019 9:25 PM