Listview sorting in ascending / descending order

Hello
I am new to winforms
What I want to do is when the user clicks on a listview control column the listview data should get sorted by that column in ascending / descending order
Please help me 
Thanks
regds
Manoj Gokhale

There's an example at the following link.
https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.listviewitemsorter%28v=vs.110%29.aspx

Similar Messages

  • How to make the listview populated by ascending / descending order wen clicked on listview column

    Hello
    I am new to winforms.
    I have a listview. I want it to toggle the sorting of the records of the listview when the columns are clicked
    Please guide me as to how to do the same.
    The code that I have attached does the sorting but it is extremely slow
    regards
    Manoj Gokhale
    //Determine whether the column is the same as the last column clicked.
    if (e.Column != sortColumn)
    // Set the sort column to the new column.
    sortColumn = e.Column;
    // Set the sort order to ascending by default.
    listView1.Sorting = System.Windows.Forms.SortOrder.Ascending;
    else
    // Determine what the last sort order was and change it.
    if (listView1.Sorting == System.Windows.Forms.SortOrder.Ascending)
    listView1.Sorting = System.Windows.Forms.SortOrder.Descending;
    else
    listView1.Sorting = System.Windows.Forms.SortOrder.Ascending;
    // Call the sort method to manually sort.
    listView1.Sort();
    // Set the ListViewItemSorter property to a new ListViewItemComparer
    // object.
    this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column, listView1.Sorting);

    Hi Manoj,
    >> The code that I have attached does the sorting but it is extremely slow
    Based on the code, I did not find the reason which caused it extremely slow. Could you share us the row count of the listview. If you have a large rows, I am afraid it is a common situation.
    In addition, you could try the code in the link below:
    # How to: Sort ListView Items
    https://msdn.microsoft.com/en-us/library/ms229643%28v=vs.90%29.aspx?=255&MSPPError=-2147217396
    # Data binding a ListView
    http://www.codeproject.com/Articles/10008/Data-binding-a-ListView
    Best Regards,
    Edward
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • How to sort data in descending order when user clicks on the column heading

    Hi
    I have a report called "Top customers", which shows the top customers for a specific product line. It displays the customer name and one column with the total amount spent in the period for each product line. By default, the leftmost product line is sorted in descending order.
    If the user wants to know who are the top customers for another product line, they simply click on the column heading to sort the list by that column.
    The problem is that when you click for the first time on a sortable column heading, Apex sorts it in ascending order; you need to click on the same column heading again to sort in descending order.
    Is it possible to change this behaviour and sort the data in descending order in the first click? So the users don't have to click twice...
    Thanks
    Luis
    PS: Apex 3 running on Oracle 10.2.0

    Luis,
    See: Can I "catch" a click on a sortable column header of a report?
    Take a look at Anton Nielsen's answer with regards to hiding a column and displaying its value instead of the sortable column.
    Asumming the following simple report query:
    select product,sales
    from <table>
    Change that into:
    select product
    ,sales*-1 as reverse_sales -- Select this one as an extra column
    ,sales -- Hide this column
    from <table>
    In your report column attributes (of column reverse_sales), html-expression, type #sales#. It then displays the normal sales. However apex will generate a 'order by 2 asc' for the first time. The '2' will refer to the sales*-1 value: sorting it asc, is the same as sorting sales descending...
    Toon

  • Iplanet page display  datas in ascending/descending order

    Hi,
    we are accessing one static path from iplanet web server. the
    url like http://localhost:8084/staticpage/Afolder/.
    The URL will display the whatever files and directories in the Afolder.
    But it display the page ,default with out sorting order.
    we want to display the page in either descendng/ascending order.
    please how can we do this one.
    please help me.
    Thanks and Regards
    Karthik

    Hi,
    The deliveries are created with respect to the Scheduling agreements.  Hence for the Scheduling agreement a span of a year and 3000-5000 Units of the product to be delivered in a phased manner of 20-40 Units would have a big thread in the sales document flow. The scheduling agreements have possibility of getting renewed.
    Hence, need was that why not we have the sales document in the descending order, by which we could see the last processed delivery.
    Best Regards,
    Lakshmana Sudhir R

  • Unable to sort profit center as ascending & Decending order in KE80 & KE30

    Hi,
    When viewing KE30/KE80 reports and navigating by a field such as profit centre, appear to be unable to sort in ascending/descending order.
    e.g. run a KE80 Report: i.e. ZPC-9000 & i.e. variant SMKT, and execute the report click on "Profit Center" under the navigation line to navigate it out to the right. Then click on the magnify glass next to the PC number (should bring up the list of all available PCs, 1259 entries found).
    From this pop-up box, unable to sort the PCs by ascending/descending order regardless of what you click.Also unable to sort the Long Text by ascending/descending order regardless of what you click
    Can anyone pls help on the above issue.We have to apply any note for this???.
    Thanks & Regards
    Mani

    Dear Mani,
    you can sort the entries by right-clicking on the column header and chosing the sorting order in the appearing menu.
    Cheers,
    Daniela

  • Sorting of calculated field in descending order

    Hi Gurus, Expert
    I have this code in BIP to get the Total Amount:
    <?xdoxslt:set_variable($_XDOCTX,’MRCTot’,0)?>
    <?for-each:ROW?>
    <?xdoxslt:set_variable($_XDOCTX,'MRCTot',xdoxslt:get_variable($_XDOCTX,'MRCTot')+(MRC_ADD_PHP+MRC_DELETE_PHP+MRC_UPDATE_PHP))?><?MRC_ADD_PHP+MRC_DELETE_PHP+MRC_UPDATE_PHP?>
    <?end for-each?>
    <?xdoxslt:get_variable($_XDOCTX,'MRCTot')?>
    Can you help me please how to sort this in Descending Order.
    Regards,
    John Paul

    <?for-each:ROW?>
    <?sort:A+B+C;'ascending';data-type='number'?>should help

  • Displaying Array Position not working in case of descending Order?

    Hi,
    I need to display the array position of the sorted array in Descending order. Here is my code.
         int[] in = {5,3,2,7};
              int[] newArr = new int[in.length];
              int[] na = new int[in.length];
              //copying into a new array
              for(int i=0;i<in.length;i++){               
                   newArr[i] = in;     
              // code for descending order
              for(int j=0;j<in.length;j++){
              Arrays.sort(in);
              na[j] = in[in.length-(1+j)];
              }the sorted array will be will be {7,5,3,2} now according to this i need to display the array position of the sorted array which should be {3,0,1,2} i tried to compare newArr[i] with na[j] but am not gettin the result that i should be getting the same comparison is working in case of Ascending Order but not descending. Any suggestions or help will be appreciated.
    Thanks and regards.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    hi,
    what you are doing is correct only, do not put sort method inside the for loop
    and postion is correct also
    int[] in = {5,3,2,7};
            int[] newArr = new int[in.length];
            int[] na = new int[in.length];
            //copying into a new array
            for(int i=0;i<in.length;i++){
                newArr[i] = in;
    Arrays.sort(in);
    // code for descending order
    for(int j=0;j<in.length;j++){
    na[j] = in[(in.length-1)-j];
    System.out.println("Val --> "+na[j]);
    System.out.println("Position --> "+j);

  • Sortable Header Ascending/ Descending Arrow is not refreshing

    Hi,
    When I clicked on the sortable Header column its showing up in the ascending/descending order with arrow up and down, results also displaying accordingly, but if I go to other screen and come back to the same screen , its still showing up the ascending/descending arrow , but the results are not showing according to the order, what parameters need to be set to not to appear that arrow if I come back from other screen. I want it to be reset, if I go back to other screen and come to this screen. I dont want that arrow to be appeared when the page loads. The arrow is showing up in ascending/descending order but the results are not showing up in that order when I come back to this page again.
    I have to log out the application for the arrow to disappear.
    Please help me
    Thanks
    Power

    Hi:
    I had the same problem here. Did you get it resolved? If so , would you please share with me?

  • How do I change the ascending/descending in emails on an iPad?

    How can I change the ascending/descending order of emails on an iPad?

    With the built-in Mail app you can't - if it's something that you want then you could see if any of the third-party email apps allow it and/or try leaving feedback for Apple.

  • Change the sort order (ascending/descending) based on parameter field

    I have created a formula on a subreport to change sorting based on variables.
    select {?Pm-@Sorting}
    case "property_type_desc ASC" :
    {owned_property.property_type_desc}
    case "property_type_desc DESC" :
    {owned_property.property_type_desc}
    default:
    ({owned_property.property_type_cd}; )
    how can I change the sort order ascending and descending using the formula??
    Thanks, Jessica

    Try this
    1. Create a parameter with 2 default values in the picklist: Descending and Ascending.
    NOTE:
    In Crystal Reports version 5 or 6, it is not possible to have a pick a parameter value from a list. The user must enter a specific value, guided by the prompting text. For example : To Sort in Ascending order type A, to sort in Descending order type D.
    u2022 On the 'Insert' menu, click 'Parameter', then click 'New'.
    u2022 Type the name and prompting text for the parameter in the corresponding boxes.
    u2022 In the 'Type' box, click 'String'.
    u2022 Click 'Set Default'.
    u2022 In the 'Value to add' box, type 'Descending' then click '>' to move it to the 'Default Values' list.
    u2022 Repeat the above step for 'Ascending'.
    u2022 Click 'OK', then click 'OK' again to return to the report.
    2. Create 2 formulas based on the field you want to change the sort direction on:
    u2022 On the 'Insert' menu, click 'Formula', then click 'New'.
    u2022 Create this formula:
    @Asc
    If {?Parameter} = "Ascending" then
    u2022 Save this formula and close the Formula Editor. This brings you back to the Formula tab of the Insert Fields dialog box.
    u2022 Click 'New' and create this formula:
    @Des
    If {?Parameter} = "Descending" then
    u2022 Save this formula and close the Formula Editor.
    u2022 Click 'Close' to return to the report.
    4. Sort the report based on these two formulas.
    u2022 On the 'Report' menu, click 'Sort Records'.
    u2022 In the 'Report Fields' list, click {@Asc} and move it to the 'Sort Fields' list.
    u2022 Under 'Sort Direction', click 'Ascending'.
    u2022 In the 'Report Fields' list, click {@Des} and move it to the 'Sort Fields' list.
    u2022 Under 'Sort Direction', click 'Descending'.
    u2022 Click 'OK' to return to the report.
    Once you preview the report you will be prompted to select a parameter value, which will determine how the report is sorted.
    Regards,
    Raghavendra

  • Using JavaScript need to Sort subsite site collection based on date in descending order

    Hi,
    Below is my code, where i need to sort the " webCollection
    = web.getSubwebsForCurrentUser(null)" web collection based on the web.get_created() in
    descending order. How could i do it any suggestions. Also i need it in JavaScript.
    <script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
    <script src="/_layouts/15/SP.js"></script>
    <script type="text/javascript">
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    ExecuteOrDelayUntilScriptLoaded(getWebProperties, "sp.js");
        function getWebProperties() {
                    webCollection = web.getSubwebsForCurrentUser(null);
            context.load(webCollection)
            //ctx.load(this.web);
            context.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
                Function.createDelegate(this, this.onFail));
        function onSuccess(sender, args) {
            //alert('web title:' + this.web.get_title() + '\n ID:' + this.web.get_id()
    + '\n Created Date:' + this.web.get_created());
            alert("Number of sites: " + webCollection.get_count());
                   var webEnumerator = webCollection.getEnumerator();
                    while (webEnumerator.moveNext()){
       var web = webEnumerator.get_current();
      alert("Title="+web.get_title() +"\n"+ "Created="+web.get_created());
        function onFail(sender, args) {
            alert('failed to get list. Error:'+args.get_message());
    //getWebProperties();
    </script>
    Thanks!
    MCTS- Please vote and mark posts as answered where appropriate.

    Hi,
    According to your post, my understanding is that you wanted to sort the subsite based on the date in descending order.
    You can refer to the following code snippets, it sorts the subsites by the date in descending order.
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    // When the body is loaded, the onload event handler executes each function whose name is contained in this array.
    _spBodyOnLoadFunctionNames.push("callCSOM");
    function callCSOM()
    $("#Button1").click(function()
    ExecuteOrDelayUntilScriptLoaded(RetriveSites, "sp.js");
    var currentcontext = null;
    var currentweb = null;
    function RetriveSites()
    currentcontext = new SP.ClientContext.get_current();
    currentweb = currentcontext.get_web();
    this.subsites = currentweb.get_webs();
    currentcontext.load(this.subsites);
    currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
    Function.createDelegate(this, this.ExecuteOnFailure));
    function ExecuteOnSuccess(sender, args)
    var subsites = '';
    var enum1 = this.subsites.getEnumerator();
    var siteCreatedTime = '';
    var array=new Array();
    while (enum1.moveNext())
    var site = enum1.get_current();
    array.push(new Array(site.get_created(),site.get_title()));
    alert(array);
    array=sortMethod(array);
    alert(array);
    function sortMethod(arr) {
    var i, j, stop, len = arr.length;
    for (i=0; i<len; i=i+1)
    for (j=1;j<len - i; j++)
    // change the "<" to ">" would be sort by the Ascending.
    if (new Date(arr[j-1][0]) < new Date(arr[j][0]))
    //swap(j, j+1);
    var temp = arr[j-1];
    arr[j-1] = arr[j];
    arr[j] = temp;
    //alert(new Date(arr[j]));
    return arr;
    function ExecuteOnFailure(sender, args) {
    alert("error");
    </script>
    <input id="Button1" type="button" value="Run Code"/>
    Results:
    Sort before:
    Sort after:
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected].
    Jason Guo
    TechNet Community Support

  • The formula field is not sorting both ascending and descending

    Dear All,
                   I am designing scoreboard the net amount contains the formula field, i sorted with asceding order by using sort,but it is not sorted both ascending or descending ,
                  Suppose if i used to sort the database field it is sorted properly  so any one help me very urgent
    Regards
    Selva.D
    Edited by: Rui Pereira on Aug 8, 2008 11:32 AM

    Dear Suda,
                     The scoreboard i designed via query print layout. So i calculated  by using formula field ie totalsales- sales return for that i used formula and i follow the below steps
    Choose repetitive area -
    > Right mouse click---> sort
    in the sorting i choose the formula uinque id and i choose Ascending then summary, after i click ok
    Suggest me the solution
    Regards
    Selva.D
    Edited by: Rui Pereira on Jul 8, 2008 5:18 PM

  • Need to sort results in a report in descending order

    Hi,
    We have OIM 10g and we need to sort the report on date in descending order. I tried this code but still the column is not getting sorted.
    Evertime I generate the report, the results are sorted only in ascending order.
    Here the stored procedure code for sorting:
    strOrderByClause := 'abc.date';
    IF strsortorder_in = 'DESC' THEN
    intSortDirection_in := 0;
    ELSE
    intSortDirection_in := 1;
    END IF;
    Please let me know if you have faced similar issue.
    Thanks,
    Kalpana.

    Hi,
    If Oracle can give you back the right sort order without any custom sorting,
    that means you should be able to get the same results in WebI.
    If the object that you pull from the universe is the wrong type (like numeric but you want it alphanumeric),
    then you can either request you designer to give you an object with the right data type,
    or you can change it by creating a report variable using
    FormatNumber([original object],"0")
    this will format the number to a number without leading zeroes, thousand separators or decimal point.
    Now you can use the object as if it came from the universe.
    So you can also use it on the x-axis of a chart.
    Btw. you can also do a custom sort on the x-axis(as long as it is an object or variable, not a formula)
    alternative, if you define a custom sort in a table block, you can state it should be used througout the document.
    (so also in the charts.
    Hope this helps,
    Marianne

  • Sorting a two dimensional array in descending order..

    Guy's I'm a beginning Java programmer. I've been struggling with finding documentation on sorting a two dimensional primitive array in descending order.. The following is my code which goes works, in ascending order. How do I modify it to make the list write out in descending order?
    class EmployeeTable
         public static void main(String[] args)
         int[][] hours = {
              {2, 4, 3, 4, 5, 8, 8},
              {7, 3, 4, 3, 3, 4, 4},
              {3, 3, 4, 3, 3, 2, 2},
              {9, 3, 4, 7, 3, 4, 1},
              {3, 5, 4, 3, 6, 3, 8},
              {3, 4, 4, 6, 3, 4, 4},
              {3, 7, 4, 8, 3, 8, 4},
              {6, 3, 5, 9, 2, 7, 9}};
         int [] total = new int [hours.length];
         for (int i = 0; i < hours.length ; i++){
              for (int j = 0; j < hours.length ; j++){
                   total[i] += hours[i][j];
         int[] index = new int[hours.length];
         sortIndex(total, index);
    for (int i = 0; i < hours.length; i++)
    System.out.println("Employee " + index[i] + " hours are: " +
    total[i]);
    static void sortIndex(int[] list, int[] indexList) {
    int currentMax;
    int currentMaxIndex;
    for (int i = 0; i < indexList.length; i++)
    indexList[i] = i;
    for (int i = list.length - 1; i >= 1; i--) {
    currentMax = list[i];
    currentMaxIndex = i;
    for (int j = i - 1; j >= 0; j--) {
    if (currentMax < list[j]) {
    currentMax = list[j];
    currentMaxIndex = j;
    // How do I make it go in descending order????
    if (currentMaxIndex != i) {
    list[currentMaxIndex] = list[i];
    list[i] = currentMax;
    int temp = indexList[i];
    indexList[i] = indexList[currentMaxIndex];
    indexList[currentMaxIndex] = temp;

    Bodie21 wrote:
    nclow all you wrote was
    "This looks to me like a homework assignment that you're asking us to solve for you. Your description of what it does isn't even correct. It doesn't sort a 2d array.
    You would probably elicit better help if you could demonstrate that you've done some work and have something specific that you don't understand."
    To me that sounds completely sarcastic. You didn't mention anything constructive besides that.. Hence I called you a male phalic organ, not a rear exit...Bodie21, OK, now you've got 90% of us who regularly contribute to this forum thinking your the pr&#105;ck. Is that what you wanted to do? If so, mission accomplished. Many will be looking for your name next time you ask for help. Rude enough for you?

  • Ascending/Descending Email Order Problem...

    Exasperating... I have set all my inboxes to show incoming mails in descending order. However, my main Inbox has to be re-set to descending every time I click on it... my other laptop running Lion doesn't exhibit this problem. Any ideas? (I've repaired permissions)... I don't want to have to trash my Mail prefs and start again...
    TIA,

    I tried this on a simple DataGrid and it worked most of the
    time (sorted ascending on the first click, descending on the second
    click), but once in a while it seemed to miss a button click, and
    then the sort did not work. When I do event.trace(target) in the
    click handler, the trace does not fire when the click event is
    missed, so I don't know how to get around this.

Maybe you are looking for

  • How do i use different Apple ID on my iPhone?

    Is there a way to use a different ID from the App Store for iMessage on mu iPhone?

  • Is this legal? 200$ iTunes cards for 99$

    Seems like one of those too good to be true things, yet they got plenty of positive feedback and ebay hasn't shut them down yet. They're selling 200$ itunes gift cards for 99$. But thing is they don't give you a gift card they give you the number off

  • Access informix NW CE 7.1

    Hi, Iu2019m working with CE 7.1 and I need access a db in informix, if I create a data source and use jpa it doesnu2019t work, any idea? Regards Janeth

  • Export shrinks entire html page, including images!

    I've just completed my first page in fireworks. When I export the png to html (with the associated sliced images) the entire site has been scaled down by about two thirds. The page width in fireworks is 940 pixels and yet the exported html file has a

  • My orkut scrapbook doesn`t open!

    hello guys... i`m having certain problems with my web page on Orkut, i cant see the scrapbook page, but only on mac...because i have another computer with windows, and there it opens please someone try to help me! thanks a lot!