Show / Hide Table of Contents

    IDataStore.SetSort(string format) Method

    .NET Standard 2.x

    Specifies the sort criteria for the DataStore.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public bool SetSort(string format);
    

    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

    A DataWindow object can have sort criteria specified as part of its definition. The SetSort method overrides the definition, providing the new sort criteria for the DataWindow object. However, it does not actually sort the rows. Call the Sort method to perform the actual sorting.

    The sort criteria for a column have one of the forms shown in the following table, depending on whether you specify the column by name or number.

    Syntax for sort order Examples
    columnname order "emp_lname A" "emp_lname asc, dept_id desc"
    # zero-based columnnumber order "#3 A"

    The following table shows the recognized values for order. These values are case insensitive. For example, as, s, AS, or S all specify a case-sensitive sort in ascending order.

    Order value Resulting sort order
    a, asc, ascending, ai, i Case-insensitive ascending
    d, desc, descending, di Case-insensitive descending
    as, s Case-sensitive ascending
    ds Case-sensitive descending

    If you omit order or specify an unrecognized string, the sort is performed in ascending order and is case insensitive. You can specify secondary sorting by specifying criteria for additional columns in the format string. Separate each column specification with a comma.

    Examples

    The following code example defines the sort criteria so that data records are sorted by budget in the descending order.

    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class SetSortExample
        {
            private readonly SchoolContext _context;
    
            public SetSortExample(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