Quantcast
Viewing all articles
Browse latest Browse all 12583

Help needed with "Sorting ListView Items by Column" code i found on the internet.

Hi,

I have found code on the internet that sorts the listview items by clicking on the column's header. The listview1_ColumnClick looks like this:

private void listView1_ColumnClick(
    object sender,
    System.Windows.Forms.ColumnClickEventArgs e)
{

    // Determine if clicked column is already the column that is being sorted.
    if (e.Column == _lvwItemComparer.SortColumn)
    {
        // Reverse the current sort direction for this column.
        if (_lvwItemComparer.Order == SortOrder.Ascending)
        {
            _lvwItemComparer.Order = SortOrder.Descending;
        }
        else
        {
            _lvwItemComparer.Order = SortOrder.Ascending;
        }
    }
    else
    {
        // Set the column number that is to be sorted; default to ascending.
        _lvwItemComparer.SortColumn = e.Column;
        _lvwItemComparer.Order = SortOrder.Ascending;
    }

    // Perform the sort with these new sort options.
    this.listView1.Sort();
}


But I need to alter this code below because what i would like is to put a button on my form and when the user clicks on it, it sorts the listview-items in the column that is specified in the code.

PLEASE can someone help me?

Greetings,

Peter Kiers





Viewing all articles
Browse latest Browse all 12583

Trending Articles