Show / Hide Table of Contents

    IDataStore.Sort(string format = null) Method

    .NET Standard 2.x

    Sorts the rows in the DataStore using the current sort criteria. You can use the format parameter to specify different sort criteria.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public bool Sort(string format = null);
    

    Parameters

    format System.String

    A string whose value is the sort criteria for the DataWindow object. The expression includes column names or zero-based numbers. A column number must be preceded by a pound sign (#).

    Returns

    System.Boolean

    Returns true if it succeeds.

    Remarks

    The Sort method uses the current sort criteria for the DataWindow object. If you do not call SetSort or use the format parameter to set the sort criteria before you call Sort, Sort uses the sort criteria specified in the DataWindow object definition.

    When the Retrieve method retrieves data for the DataStore, it applies the sort criteria that were defined for the DataWindow object, if any. You need to call Sort only after you change the sort criteria with SetSort or if the data has changed because of processing.

    Examples

    The following code example sorts data records by budget in the descending order.

    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class SortExample
        {
            private readonly SchoolContext _context;
    
            public SortExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var datastore = new DataStore("d_department", _context);
    
                datastore.Retrieve();
    
                string OutPutValue;
                OutPutValue = "";
    
                // Gets values for the budget column in DataStore
                for (int i = 0; i < datastore.RowCount; i++)
                {
                    OutPutValue += datastore.GetItemNumber(i, "Budget").ToString();
                    if (i < datastore.RowCount - 1)
                    {
                        OutPutValue += ", ";
                    }
                }
    
                Console.WriteLine("Before SetSort, Budget Value List: {0}",
                    OutPutValue);
    
                // Calls SetSort to sort data by budget in descending order.
                // Calls Sort to apply the sort.
                datastore.SetSort("Budget D");
                datastore.Sort();
    
                OutPutValue = "";
    
                // Gets values for the budget column in DataStore after sort.
                for (int i = 0; i < datastore.RowCount; i++)
                {
                    OutPutValue += datastore.GetItemNumber(i, "Budget").ToString();
                    if (i < datastore.RowCount - 1)
                    {
                        OutPutValue += ", ";
                    }
                }
    
                Console.WriteLine("After SetSort, Budget Value List: {0}",
                    OutPutValue);
    
                /*This code produces the following output:
                
                Before SetSort, Budget Value List: 350000, 120000, 200000, 250000
                After SetSort, Budget Value List: 350000, 250000, 200000, 120000   
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon